关于Android获取当前位置的问题

发布于 2024-09-26 02:57:13 字数 429 浏览 10 评论 0原文

我对获取设备的当前位置有几个疑问。

我相信唯一的方法是使用 requestLocationUpdates(....)

  1. 如果我订阅 requestLocationUpdates... 并将持续时间设置为 1 小时,并且 1 小时后如果我的手机处于睡眠状态(或者在这 1 小时内我重新启动了手机),侦听器是否仍然工作?

答:如果是 - 1 小时后,当我收到有关位置的更新时,我想将持续时间更改为 2 小时。有办法做到这一点吗?如果没有,我可以调用removeUpdates,然后立即调用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(....).

  1. 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 removeUpdates, 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-10-03 02:57:13

我不是 100% 确定,但如果您重新启动,您的电话服务不会再次启动,也如手册中所述:

minTime - the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

这只是更新时间的提示,但并不可靠。
您的做法应该是创建一个服务,该服务应该使用 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:

minTime - the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文