Appcelerator Titanium Android 后台定位服务 [英] Appcelerator Titanium Android background location service

查看:35
本文介绍了Appcelerator Titanium 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.

我发现 Ti.App.iOS.backgroundService 可以为 iphone 执行此操作,但是如何在 android 中启动后台服务以及如何在找到特定纬度和经度时呈现本地通知.

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. android 中的后台位置服务
  2. android 等价于 localnotification

推荐答案

对于 Android 上的背景地理,我使用以下策略.

For background geo on Android I use the below strategy.

1) 在我的 app.js 中,我添加了一个包含我的地理逻辑的 Titanium.App.addEventListener

1) In my app.js I add an Titanium.App.addEventListener that contains my geo logic

厨房水槽示例 https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/app_events.js

2) 然后我创建一个每 15 分钟触发一次的 ServiceIntent

2) I then create a ServiceIntent that fires every 15 minutes

厨房水槽示例 https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/android_services.js

请注意,您调用的这个 service.js 需要在您的 android 文件夹中,即使您只有一个 android 项目.

Please note this service.js you call needs to be in your android folder, even if you have an android only project.

3) 服务检查个人移动的距离是否超过 1 公里,如果移动,则触发步骤 1 中定义的应用事件.

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.

希望这会有所帮助.

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

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