Android: How to turn screen on and off programmatically?

后端 未结 16 2057
醉酒成梦
醉酒成梦 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:27

    To keep screen on:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    Back to screen default mode: just clear the flag FLAG_KEEP_SCREEN_ON

    getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

提交回复
热议问题