Appcelerator Titanium Android background location service - android

I am trying to make an app , where if the user enters a particular region, he will get an alert. And that will work even if the app is in background.
I found Ti.App.iOS.backgroundService to do that for iphone but how to start the background service in android and how to present local notification kind thing when particular latitude and longitude is found.
so basically my questions are :-
background location service in android
android equivalent for localnotification

For background geo on Android I use the below strategy.
1) In my app.js I add an Titanium.App.addEventListener that contains my geo logic
Kitchen Sink Sample https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/app_events.js
2) I then create a ServiceIntent that fires every 15 minutes
Kitchen Sink Sample https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/android_services.js
Please note this service.js you call needs to be in your android folder, even if you have an android only project.
3) The service checks if the individual has moved more then 1KM, if they have it fires the App Event defined in step 1.
Using this strategy and adjusting my service time and distance calculation I've been able to reduce most of my battery drain issues that I had with the built in location event with distance filter.
Hope this helps.

Related

How to use GPS Service in android

I'm working on Android project that related to GPS I still new to android so I don't know a lot about it.
My project is an app where it calculates the distance between user location and a specified other location so if the distance is less than (X) say 1KM the app will send a notification to the user.[[I know how to calculate the distance between two
locations]].
My problem is: how can I do this even if the user didn't open the app (I mean if there's anyway that I can make the app calculates the distance in the background while the app is closed).so I want the GPS feature works in the background.
Thanks in Advance.
You can use a service for background process.
For your question for getting location, you should try these links:
Best way to get user GPS location in background in Android
Get GPS location via a service in Android
My solution for this problem was simply :-
you can use Services for working in the background (when the Activity isn't showing)
check this : -Get GPS location via a service in Android
**if you want this service to run for ever, even if the app is closed/killed you can use broadcast receivers **
To get the app to run in the background, you'll need to learn about a service.
Service is a service that causes applications to run in the background such as gps, notification and more ..
link:
https://developer.android.com/reference/android/app/Service.html
User services. They are simple to use and all you need.
Here is the documentation.
A service is another component of an android application (like activity). You need to define the service in manifest. After that you could start the device using startService (intent). If you need to take some info (communicate with one activity) you can use bindService instead of startService. (Also need to implement onBind).
Another solution is to sendData using a broadcast receiver. Or you can simple set a notification in service and use it.

IOS App auto running in background

I'm developing an IOS / Android gps based application that needs to update location always (or after significant location change). Similar to Life360 family locator app. This app doesn't need to start at all and yet when you open the app it has all your location data captured for a week. If I'm checking on my kids location and they don't have their phone actively running the app, I still get the real-time location and their gps history.
How is this accomplished? It seems that the app is logging gps data, not only when in foreground and background but when not running at all. Is there a special run-mode these apps use?
thanks all!
Mike
I can only speak for iOS.
On iOS you can register for significant location changes, and your app will get notified in the background when a location change event occurs (and even get launched in the background if it had been terminated). You can then request background time and transmit your updated location information to your server.

PhoneGap (Cordova) start tracking GPS on a specific time

I am developing a Phonegap application which requires GPS tracking. The tracking is required only at a certain time. For example, the event start at 5 o clock, then I want to start tracking at 5 o clock only. Any option for doing it background. The app is developing for iOS and Android.
Is there any option for doing this. Any help would be appreciated. Thanks in advance.
Maybe this will help you -> Can i schedule events in Phonegap but i think, this will only work on Android. I don't know how you could realise this on iOS.
You can use AlermManager class in that create broadcast when broadcast wakeup then u can call
gps enable and track location according to that same for stop gps location also

Android Geofencing sample app only works if another app is open using GPS

I am working with the Geofence API Sample application I've got it running and seems to work alright. I did make the modifications to it to use BroadcastReceiver instead of the IntentService.
But I will only get the notifications if I have some other app open that is using GPS such as Maps, or GPS Tester app.
If I don't have one of those apps open and I walk into the geofence zone nothing happens. But as soon as I launch one of them I will get the notification within a few seconds.
I ended up creating a service that forces the GPS to stay active by requesting location updates on a relatively quick interval.
While this is admittedly a poor work around for a "real" application. It worked for my purposes. In which I needed to be able to present a working proof of concept to an audience, which impeded my ability to use a geo points which were further spread out.
Even I too had a struggle with getting Geofence notification as soon I entered Geofence or Exit the one.There were always delays in notifications until I found a really nice Location Library called little-fluffy-location-library which serves my purpose.Location updates will be broadcast to your app periodically.
According the Documentation it says that:
The library works by using Froyo's passive location listener (only possible with Android 2.2 and up, hence why it works best with it), which listens to location updates requested by other apps on your phone. The most accurate location is broadcast to your app approximately every 15 minutes. If a location update hasn't been received from another app for an hour, the library forces a location update of its own.
I think you should give a try with this Library and Let me know if it works for you!!

Appinventor data triggered by GPS location

I want to create an app in appinventor which will be using gps coordinates to show some data. What I mean is that I want to make an app which will show a message whenever you go to an exact position. I already got the GPS coding that needs to be done but I'm not sure if I can save the data to somehow inside the gps. Im new at this so don't be too harsh with me! Is it even possible to do something like that in appinventor?
Unfortunately what you're describing is a service, in which your program runs in the background waiting for the GPS to hit a trigger location. App Inventor at his time does not have the capability to let you program a service.
You have to open your app manually and have it run in the background. As long as all permissions are enabled, it can then send push notifications using the appropriate block. I personally haven't experimented with what they display, but when properly done, it can show an image and text at the same time, one, or the other.
This means you could call the GPS when you reach a certain location, send a push notification with said text/image, which you can then view by the pulldown bar.
You could also have the app send yourself information via a text, replacing this with the push notification block, whenever you reach a certain latitude and longitude.

Categories

Resources