android schedule 参数,android – requestLocationUpdates minTime参数的用途

我正在创建一个应用程序(用于教育目的),每30分钟记录一次用户的位置,并使用户可以查看地图上的所有位置.我不希望更新频率超过30分钟,但确实如此.

这就是我调用requestLocationUpdates的方式:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * 60 * 1000, 0, pe);

现在,文档清楚地说:

The elapsed time between location updates will never be less than minTime

但我确实在这里看到了一些不同的答案(例如This answer).

看起来我无法通过GPS获得更新. GPS图标永远不会关闭,更新率大于1更新/秒.所以我在这里有两个问题:

> minTime参数不能实现其目的,甚至不作为提示(是的,提示30分钟更新率导致超过更新秒…).它做了什么呢?

>还有其他办法吗?我不希望GPS一直启用,因为它会消耗我的电池太快.也许我可以安排每30分钟重复一次的警报,并调用requestSingleUpdate?

解决方法:

The minTime parameter doesn’t fulfill its purpose, not even as a hint (Yea, a hint to 30 minutes update rate leads to more than update a second…). What does it do, then?

从Jellybean开始,设备必须遵守minTime参数,因此它有一个目的(现在).

Is there any other way to do it? I don’t want the GPS to be enabled all the time because it will consume my battery too fast. Maybe I could schedule alarms repeating each 30 minutes, and call requestSingleUpdate?

是的,使用Handler每30分钟使用requestSingleUpdate()请求一次更新.

我之前在previous question中已经解决了这个问题,让我知道该答案中的代码是否有帮助,如果您有任何问题则无法解决.

标签:android,gps,locationmanager

来源: https://codeday.me/bug/20190529/1180669.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值