Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON question

Tags:

android

flags

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!

like image 846
Johan Avatar asked Jan 06 '11 23:01

Johan


1 Answers

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.

like image 170
Falmarri Avatar answered Sep 20 '22 19:09

Falmarri