1

I'm using this codes for turn on the screen.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
    | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

But after first using this codes, the screen never turn off again. I want to do turn on the screen but after that the screen again turn off when end of screen off time. How can I do it?

  • I don't understand the behavior you want here. Can you rewrite the "I want to do turn on the screen but after that the screen again turn off when end of screen off time." part? – ddb Jul 25 '16 at 09:43
  • anyway, maybe this question is a duplicate of http://stackoverflow.com/questions/4807634/disable-keep-screen-on – ddb Jul 25 '16 at 09:44

1 Answers1

1

Turning the screen on:

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

To turn off, you should clear the flag that you have set:

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

Note that an application cannot force the screen to turn off, it can just release locks that it holds, so the system could turn the screen off as it would without your app.

Amir Uval
  • 14,425
  • 4
  • 50
  • 74