How to tell if device is sleeping

后端 未结 4 1077
我寻月下人不归
我寻月下人不归 2020-12-31 09:40

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

4条回答
  •  再見小時候
    2020-12-31 10:25

    You can try the KeyguardManager to check if the device is locked. Here is some code (I haven't tried this myself):

    KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    boolean showing = kgMgr.inKeyguardRestrictedInputMode();
    

    Good luck!

提交回复
热议问题