Appcelerator Titanium Android background location service

廉价感情. 提交于 2020-01-01 03:37:07

问题


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 :-

  1. background location service in android
  2. android equivalent for localnotification

回答1:


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.



来源:https://stackoverflow.com/questions/5786489/appcelerator-titanium-android-background-location-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!