Android: How to turn screen on and off programmatically?

后端 未结 16 2312
醉酒成梦
醉酒成梦 2020-11-22 13:05

Before marking this post as a \"duplicate\", I am writing this post because no other post holds the solution to the problem.

I am trying to turn off the device, then

16条回答
  •  天涯浪人
    2020-11-22 13:41

    As per Android API 28 and above you need to do the following to turn on the screen

    setShowWhenLocked(true); 
    setTurnScreenOn(true); 
    KeyguardManager keyguardManager = (KeyguardManager)
    getSystemService(Context.KEYGUARD_SERVICE);
    keyguardManager.requestDismissKeyguard(this, null);
    

提交回复
热议问题