android schedule 参数,android – requestLocationUpdates minTime参数的用途
我正在创建一个应用程序(用于教育目的),每30分钟记录一次用户的位置,并使用户可以查看地图上的所有位置.我不希望更新频率超过30分钟,但确实如此.这就是我调用requestLocationUpdates的方式:locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,30 * 60 * 1000,0, pe);现...
我正在创建一个应用程序(用于教育目的),每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)