我正在尝试制作一个应用程序,如果用户进入特定区域,他会收到警报。即使应用程序处于后台,这也将起作用。
我发现 Ti.App.iOS.backgroundService 可以为 iphone 执行此操作,但如何在 android 中启动后台服务以及如何在找到特定纬度和经度时呈现本地通知之类的事情。
所以基本上我的问题是:-
- Android中的后台定位服务
- android 相当于 localnotification
对于 Android 上的背景地理,我使用以下策略。
1)在我的app.js中,我添加了一个Titanium.App.addEventListener,其中包含我的地理逻辑
厨房水槽样品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) 然后我创建一个每 15 分钟触发一次的 ServiceIntent
厨房水槽样品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 中定义的应用程序事件。
使用此策略并调整我的服务时间和距离计算,我已经能够减少使用带有距离过滤器的内置位置事件所遇到的大部分电池消耗问题。
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)