如何判断设备处于睡眠状态如何判断、睡眠、状态、设备

2023-09-06 01:04:35 作者:哥,依旧颓废

下面是我的方案。我有一个应用程序,是玩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()

 
精彩推荐
图片推荐