确定 Android 手机与已知点的接近程度,同时节省电量
我正在尝试确定 Android 用户是否非常接近预定位置列表。我希望以最少的手机电池消耗来完成此操作。我看到的实现此目的的两种机制是 接近警报 和请求位置更新。两种方法各有什么优缺点?其中一种对电池的影响会比另一种小吗?无论哪种情况,我都会猜测具体的 使用的位置管理器会对电源使用产生一些影响(现有的 Stack Overflow 答案)。
I am trying to determine if an Android user has had a close proximity to a list of predetermined locations. I'd like to do this with the least amount of drain on the phone's battery. The two mechanisms I see for accomplishing this are proximity alerts and requesting location updates. What are the pros and cons of the two methods? Will one have less affect on the battery than the other? In either case I would guess the specific location manager used would have some affect power usage (existing Stack Overflow answer).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就电池使用而言,位置更新可能比接近警报便宜。
由于
addProximityAlert
同时使用NETWORK_PROVIDER
和GPS_PROVIDER
,您将无法选择要使用的提供商。此外,虽然文档表明它将屏幕关闭时的邻近检查限制为每四分钟一次,但我找不到支持此类功能的代码,而我能找到的基本上是 调用requestLocationUpdates
,最小时间间隔提示为1000毫秒。由于建议后台服务使用超过60000毫秒的值,我怀疑它会更便宜以较大的最小时间间隔和NETWORK_PROVIDER
直接调用requestLocationUpdates
。Location updates are probably less expensive than proximity alerts in terms of battery usage.
Since
addProximityAlert
uses bothNETWORK_PROVIDER
andGPS_PROVIDER
, you lose the ability to pick which provider you want to use. Additionally, while the documentation suggests that it limits proximity checks to once every four minutes when the screen is off, I can't find the code to support such functionality and what I can find is essentially a call torequestLocationUpdates
with a minimum time interval hint of 1000 ms. Since it is recommended that background services use values over 60000 ms, I suspect that it would be less expensive to callrequestLocationUpdates
directy with a large minimum time interval andNETWORK_PROVIDER
.