将 ACTION_SCREEN_ON 替换为 ACTION_USER_PRESENT?
我有一个长期运行的服务正在监听传感器输入。为了节省电池电量,我在 ACTION_SCREEN_OFF 时停止了传感器采样,并在 ACTION_SCREEN_ON 时再次启动采样。
然而,我通常只是打开手机快速浏览一下锁定屏幕上的时钟(以检查当前时间),然后再次关闭手机而不解锁手机。在这种情况下,没有理由旋转传感器然后立即关闭。
因此,我尝试在广播侦听器中将 ACTION_SCREEN_ON 替换为 ACTION_USER_PRESENT 。除了一种特殊情况外,这种方法工作得很好:当屏幕关闭并且我立即按下电源按钮(或主页按钮)时,会跳过锁定屏幕。然后 ACTION_USER_PRESENT 永远不会收到,只收到 ACTION_SCREEN_ON。
有没有办法让我的广播接收器在收到 ACTION_SCREEN_ON 后知道屏幕锁定是否处于活动状态并稍后期待 ACTION_USER_PRESENT ?或者,如果跳过锁定屏幕,则不等待 ACTION_USER_PRESENT 并立即重新启动采样?
I have a long-running service listening for sensor input. To conserve battery power, I've stopped the sampling of the sensors on ACTION_SCREEN_OFF and started it back up again on ACTION_SCREEN_ON.
Often, however, I just turn my phone on for a quick glance at the clock on the lock-screen (to check the current time) and then turn it off again without unlocking the phone. In that case, there's no reason to spin up the sensors just to shut then down again at once.
So therefore I tried replacing ACTION_SCREEN_ON with ACTION_USER_PRESENT in my broadcast listener. This worked fine except for one special case: When the screen goes off and I press the power button (or home button) at once, the lock screen is skipped. And then the ACTION_USER_PRESENT is never received, only the ACTION_SCREEN_ON.
Is there a way for me broadcast receiver, upon receiving an ACTION_SCREEN_ON to know if the screen-lock is active and to expect a ACTION_USER_PRESENT later? Or if the lock-screen is skipped, not to wait upon ACTION_USER_PRESENT and go ahead and restart the sampling at once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直到android 4.4,如果打开屏幕并禁用锁定屏幕,则只会触发action_screen_on。从Android 5.0中,在这种情况下,Action_screen_on和Action_user_present均被触发。
Till Android 4.4, if screen is turned on and lock screen is disabled, only ACTION_SCREEN_ON is fired. From Android 5.0, in this case, both ACTION_SCREEN_ON and ACTION_USER_PRESENT are fired.