在 Android 上持续监控加速度传感器
我需要一项持续监控加速度计传感器的服务。我知道,在过去,如果不阻止显示屏关闭,就不可能做到这一点,这对电池寿命来说当然是很糟糕的。
我的问题是 - 有没有一种好方法来实现在后台持续运行的节能加速计监视器?
I need to have a service which constantly monitors the accelerometer sensor. I know that in the past it was not possible to do so without preventing the display from turning off, which is of course awful for battery life.
My question is - is there a good way to implement power efficient accelerometer monitor which would constantly run in the background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让您的服务实现 SensorEventListener。然后将您的服务注册到 SensorManager。
我为您检查了有关传感器的文档,我相信 SensorManager 解答您的问题。您提出的每个问题都在第二段中得到了解决。
have your Service implement SensorEventListener. Then register your Service to the SensorManager.
I checked the docs about sensors for you and I believe the header for SensorManager answers your questions. Every issue you have brought up was addressed in the second paragraph.
当所有手机的屏幕都可靠关闭时,您无法使用加速计。它适用于某些手机,但不适用于其他手机。请参阅 https://code.google.com/p/android/issues /detail?id=11028 查看开放的错误报告。
另外,这个问题与 Android Workaround for non - 屏幕关闭时传感器工作
You cannot use the accelerometer when the screen is off reliably across all phones. It works for some phones, but not others. See https://code.google.com/p/android/issues/detail?id=11028 for an open bug report.
Also, this question is a duplicate of Android Workaround for non-working sensors when screen is off