Android: WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON question
Asked Answered
O

2

13

Im using the following code to keep the screen on:

this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Is there any way to disable/remove the FLAG_KEEP_SCREEN_ON later in the code? (I want the screen to fadeout normally).

Thanks!

Obau answered 6/1, 2011 at 23:9 Comment(1)
you can simply clearFlags.. getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);Overturf
C
29

You could probably do something like this

this.getWindow().setFlags(this.getWindow().getFlags() & ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

Did you look at the API? There's also this method

http://developer.android.com/reference/android/view/Window.html#clearFlags%28int%29

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

I have not tried this either yet.

I imagine this will work to check if the flag is set:

this.getWindow().getFlags() & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

Edit: As per the comments, apparently this is how you get the value of the flag.

this.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

There might be a method for that too, you should look at the API doc.

Casaubon answered 7/1, 2011 at 0:7 Comment(7)
Hmm on the second "getWindow" eclipse tells me that "getWindow cannot be resolved or is not a field"Obau
I meant getWindow(). But I'm not entirely certain the getFlags method works like that. I didn't actually pull up the apiCasaubon
'this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);' works. Is there an easy way to check if the flag is active or not (if the app is in fullscreen mode)?Obau
There is no getFlags() function in the Window class.Stowage
'this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);' Worked great for me as well. Thank you!Krauss
There is no getFlags() function, but you you can get them by calling getAttributes().flagsHandstand
Thanks Jon! It worked well for me. Falmarri you might want to edit your answer as the getFlags() part is actually wrong.Morpho
O
2

Try this

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

Also read this

Overturf answered 16/6, 2015 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.