Appcelerator的钛Android的后台位置服务 [英] Appcelerator Titanium Android background location service

查看:181
本文介绍了Appcelerator的钛Android的后台位置服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个应用程序,在那里,如果用户进入一个特定的区域,他将得到一个警告。这将工作,即使该应用程序是在后台。

我发现Ti.App.iOS.backgroundService做就是iPhone,但如何启动后台服务在Android和如何present时,特别是经度和纬度发现本地通知样的事情。

所以基本上我的问题是: -

  1. 后台位置的机器人
  2. 服务
  3. 安卓相当于localnotification
解决方案

有关背景地理Android上我用的是下面的策略。

1)在我app.js我添加包含我的地缘逻辑的Titanium.App.addEventListener

厨房水槽样品<一href="https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/app_events.js">https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/app_events.js

2)然后,我创建一个ServiceIntent将触发每隔15分钟

厨房水槽样品<一href="https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/android_services.js">https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/android_services.js

请注意,这service.js你打电话需要在你的android文件夹,即使你有一个Android唯一项目。

3)如果个人已经转移更多的则1KM,如果他们有它触发的应用程序事件在步骤1中定义的服务检查。

采用这种策略,调整我的服务时间和距离计算我已经能够减少我的大多数,我曾与内置的定位事件与距离滤波器的电池消耗的问题。

希望这有助于。

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

解决方案

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.

这篇关于Appcelerator的钛Android的后台位置服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆