How to tell if device is sleeping

后端 未结 4 1080
我寻月下人不归
我寻月下人不归 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:24

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

    tells if the screen is on. So, it gets true if the screen is on but the device is locked. Instead,

    inKeyguardRestrictedInputMode()
    

    gets true just if the device is locked.

提交回复
热议问题