Android 屏幕关闭时传感器不工作的解决方法
[编辑:删除所有提及的 Android 版本 - 该问题存在于所有版本的 Android 上]
背景:当屏幕关闭时,许多 Android 手机不会通过在屏幕关闭时调用 onSensorChanged() 来为加速度计读数的应用程序提供更新。此行为在 SO 上进行了讨论,并在此处进一步记录 http://code.google.com/p/android/issues/detail?id=3708< /a>
在某些手机(Nexus S、Droid X2...)上,仅当值发生重大变化时才提供加速度计值。例如,坐在桌子上,每分钟可能有一次或零次更新
为了生成跨手机型号的稳健代码,我如何区分每次屏幕关闭时缺少更新事件与缺少更新每不运动?我应该维护手机型号数据库吗?
[Edit: Removed all mention of Android version - the issue is present on all versions of android]
Background: When the screen is off, many Android phones do not provide updates to applications of Accelerometer readings by calling onSensorChanged() when the screen is off. This behavior is discussed on S.O. and is further documented here
http://code.google.com/p/android/issues/detail?id=3708
On some phones (Nexus S, Droid X2, ...) accelerometer values are only provided when there is a significant change in value. Sitting still on a table, for example, there might be one or zero updates per minute
In order to produce code that is robust across phone models, how am I to distinguish between a lack of update events per screen off, vs. lack of updates per non-movement? Should I maintain a database of phone models?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将很难被发现。 Android的API提供了一种控制Wake Lock的方法。但制造商在将其实施到自己的操作系统方面做得非常糟糕。太糟糕了。您需要获取 PARTIAL_WAKE_LOCK 以在屏幕关闭时保持手机 CPU 运行。
然而,并非所有设备都使用此功能并且不会响应 - 有些设备有一半响应 - 有些设备响应很好。
阅读上面的评论后,我可以告诉你我使用过的大多数 2.3+ 设备仍然没有实现部分唤醒锁。
我个人不会依赖制造商控制的东西,因为市场是如此分散。我会尝试找到一种方法来通过不同的解决方案获得我正在寻找的功能。
希望这有帮助。
This will be hard to detect. Android's API provides a way to control the Wake Lock. But manufacturers have done a TERRIBLE job of implementing this into the OS on their side. Just TERRIBLE. You would need to grab a PARTIAL_WAKE_LOCK to keep the phones CPU running when the screen is turned off.
However not all devices use this and will not respond - some half/half respond - and some respond great.
After reading the comments above I can tell you the majority of devices with 2.3+ I have used still do not implement the partial wake lock still.
I personally would not rely on something the manufacturer controls because the market is SO fragmented. I would try to find a way to get the functionality I'm looking for with a different solution.
Hope this helps.
我两天来一直在寻找这个问题的解决方案。但还是没有发现什么有用的东西。
在这篇文章这里< /a>,作者 Bruno Albuquerque,有一些东西可以对摩托罗拉手机有所帮助,但它不是通用的。
我相信@jjNford关于制造商对此有所了解的说法是正确的,你能发布任何相关信息吗?
此处是 2009 年以来的错误报告
I've been looking for a solution for this problem for two days now. But still didn't find anything useful.
At this post here, by Bruno Albuquerque there's something that could help with motorola phones but it's not generic.
I believe @jjNford is right about manufactures have a finger on that, can you post any info about that?
Here is a bug report about that dated from 2009