Android: How to turn screen on and off programmatically?

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

    Regarding to Android documentation it can be achieve by using following code line:

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

    I have added this in my onCreate method and it works fine.

    On the link you will find different ways to achieve this and general explanation as well.

    Link to the documenation: https://developer.android.com/training/scheduling/wakelock.html

提交回复
热议问题