关于Android获取当前位置的问题
我对获取设备的当前位置有几个疑问。
我相信唯一的方法是使用 requestLocationUpdates(....)
。
- 如果我订阅 requestLocationUpdates... 并将持续时间设置为 1 小时,并且 1 小时后如果我的手机处于睡眠状态(或者在这 1 小时内我重新启动了手机),侦听器是否仍然工作?
答:如果是 - 1 小时后,当我收到有关位置的更新时,我想将持续时间更改为 2 小时。有办法做到这一点吗?如果没有,我可以调用removeUpdate
s,然后立即调用requestLocationUpdates,持续时间为2小时吗?
B. 如果否 - 我计划设置一个闹钟在 1 小时后响起,然后调用removeUpdates &在警报接收器中请求位置更新。这是正确的策略吗?
I have few questions about getting current location of the device.
I believe only way to do that is using requestLocationUpdates(....)
.
- if I subscribe to requestLocationUpdates... with duration set to 1 hour and after 1 hour if my phone is sleeping (or during that 1 hour I rebooted my phone), does the listener still work?
A. If yes - After 1 hour, when I get update about location, I want to change duration to 2 hours. Is there a way to do that? If not, can I call removeUpdate
s, and immediately call requestLocationUpdates with duration as 2 hours?
B. If No - I was planning to set an alarm to go off after 1 hour, and call removeUpdates & requestLocationUpdates in the alarm receiver. Is that right strategy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 确定,但如果您重新启动,您的电话服务不会再次启动,也如手册中所述:
这只是更新时间的提示,但并不可靠。
您的做法应该是创建一个服务,该服务应该使用 Handler 和 postDelayed 在可运行对象中设置定时操作。我希望我有所帮助。
I'm not 100% sure but If you reboot your phone service isn't started again, also as is written in a manual:
This is only a hint for update time but it's not reliable.
Your practice should be to make a Service which should use Handler and postDelayed to set timed action within a runnable. I hope I helped.