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.
精彩评论