当我的手机屏幕关闭时,无法检测到震动事件
在我的应用程序中,我想检测摇动事件,并且我正在使用 SensorEventListener,当我的活动在前台运行时,代码工作正常。但是当我按下手机的锁定按钮锁定屏幕时,无法检测到震动事件。我已经在 Samsung gts5360 上测试了我的代码。但相同的代码在 sony ericssion xperia mini pro 上运行良好。实际上,当我将设备闲置大约 1 秒时,我的三星手机没有检测到震动事件。锁定设备后 45 秒。
然后我摇动手机,它没有检测到摇动,但是当我在几秒钟延迟后摇动手机时,它开始监听摇动。我的三星手机的这种行为并不一致。它会在随机时间后开始和停止监听震动事件。
现在我的问题是“这是 Android 功能吗?当屏幕锁定/关闭时,设备不会检测到震动事件?”。
如果是,那么我的三星手机如何在锁定手机几秒钟后开始/停止监听?
当“Sony ericssion xperia mini pro”屏幕锁定/关闭时,它如何连续监听震动事件?
此功能是否因供应商而异?
如果有人需要我的代码,请告诉我,我会提供。
In my application I want to detect the shake event and I'm using SensorEventListener, the code is working fine when my activity is running in foreground. But when I press the lock button of the phone to lock the screen, the shake event can't be detected. I have tested my code on the Samsung gts5360. But the same code is working fine on sony ericssion xperia mini pro. Actually my Samsung phone is not detecting the shake events when I leave the device idle for approx. 45 seconds, after locking the device.
Then I shake the phone, it does not detect the shake, but when I shake phone after several seconds delay it starts listening the shake. This behavior of my samsung phone is not consistent. It starts and stop listening the shake event after a random amount of time.
Now my question is that "Is this the android feature that the device does not detects a shake event when the screen is lock/Off ?".
If it is, then how my samsung phone starts/stops listening after some seconds of locking the phone?
And how it is continuously listening the shake event when screen is lock/off in "Sony ericssion xperia mini pro"?.
Is this feature vary vendor to vendor?
If some body needs my code then let me know,I will provide it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是很长一段时间以来,对于屏幕关闭时如何处理传感器没有一致的标准。有些设备允许其继续工作,而另一些则不允许。最终,Android 团队决定,要使其正常工作,应用程序应该为此类操作获取部分唤醒锁:
需要此权限:
"android.permission.WAKE_LOCK"
您需要确保释放完成后唤醒锁定,以便 CPU 可以完全进入睡眠状态。
即使有了这一切,它也可能行不通。我发现 LG 手机最近不太可能支持背景传感器。此外,许多摩托罗拉手机不需要唤醒锁,只需在屏幕关闭时重新注册传感器即可。
The problem is for a long time there has been no consistent standard for what to do with sensors when the screen goes off. Some devices allow it to keep working and others do not. Eventually the Android team decided that for it to work an application should acquire a partial wake lock for this kind of operation:
This permission is needed:
"android.permission.WAKE_LOCK"
You need to make sure you release the wake lock when you are done with it so the CPU can go fully to sleep.
Even with all of this it may not work. I've found that LG phones most recently are less likely to support background sensors. Also many Motorola phones don't require a wake lock but instead just need to re-register for the sensor when the screen goes off.