Android - 使用 LocationManager.requestLocationUpdates 时,我需要 WakeLock 吗?

发布于 2024-09-25 10:12:55 字数 273 浏览 1 评论 0原文

我的应用程序使用启动服务的 BroastcastReceiver 警报定期检查位置。我知道我应该在启动服务之前获取唤醒锁,但我的问题是我什么时候可以释放它?

如果我在调用 requestLocationUpdates 后释放唤醒锁,设备是否可以进入睡眠状态而不调用我的 LocationListener,或者设备是否始终唤醒以提供更新并保持唤醒状态,直到回调完成回来了?我不愿意保留唤醒锁,因为这会阻止设备在更新之间休眠,直到我完成定位。

My app periodically checks the location using an alarm to a BroastcastReceiver that starts a service. I know I should acquire a wakelock before I start the service but my question is when can I release it?

If I release the wakelock after calling requestLocationUpdates, can the device go to sleep and not call my LocationListener or will the device always wake to deliver updates and stay awake until the callback has returned? I'm reluctant to hold onto the wakelock because that would prevent the device from sleeping between updates until I'm done with the location.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

彩扇题诗 2024-10-02 10:12:55

因此,根据我的经验(并在此处的评论中确认),在调用 requestLocationUpdates 后释放唤醒锁似乎不是问题。不幸的是,获得明确答案的唯一方法是询问平台开发人员,但我收到了 无响应

So based on my experience (and confirmed in the comments here), releasing the wake lock after after calling requestLocationUpdates doesn't seem to be a problem. Unfortunately, the only way to get a definitive answer is to ask a platform developer, but I've received no response.

野の 2024-10-02 10:12:55

检查Android系统设置中的省电模式:必须禁用它才能允许位置管理器在屏幕关闭时生成更新位置;在三星 A5 上进行测试;我花了两天时间才找到这个解决方案:-)

check for power saving mode in Android system settings: it must be disable to permit location manager to generate update location when the screen is off; tested on Samsung A5; I took two days to find this solution :-)

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