如何判断设备处于睡眠状态 [英] How to tell if device is sleeping

查看:144
本文介绍了如何判断设备处于睡眠状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的方案。我有一个应用程序,是玩backgound声音。使用的BroadcastReceiver我可以告诉大家,当显示器关闭,然后杀的声音。我也可以告诉我们,如果屏幕将自动重新打开。但是,如果该装置处于锁定状态,我不想音频启动。因此,我等待ACTION_USER_ preSENT意图信号。也就是说,不同之处在于,如果用户打开屏幕的背面上后,很快就被关闭,你没有得到的锁屏或ACTION_USER_ preSENT消息的所有作品。那么,有没有办法告诉,当屏幕开启回来,如果设备被锁定或没有,我想也意味着睡觉或不?

解决方案

 ((电源管理器)getSystemService(Context.POWER_SERVICE))。isScreenOn()
 

Here's my scenario. I have an app that is playing backgound sounds. Using the BroadcastReceiver I can tell when the display turns off, and then kill the sounds. I can also tell if the screen turns back on. However, if the device is in the lock state I don't want the audio to start. Therefore I wait for the ACTION_USER_PRESENT intent to signal. That all works, except that if the user turns the screen back on quickly after it was turned off, you don't get the lock screen or the ACTION_USER_PRESENT message. So, is there a way to tell, when the screen turns back on, if the device is locked or not, which I guess also means sleeping or not?

解决方案

((PowerManager) getSystemService(Context.POWER_SERVICE)).isScreenOn()

这篇关于如何判断设备处于睡眠状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆