简体   繁体   中英

Android setting screen brightness to 0 turns off the screen - how to avoid

In Android 2.3.3, I'm trying to set the screen brightness to 0 with this code:

Window myWindow = getWindow();
WindowManager.LayoutParams winParams = myWindow.getAttributes();
winParams.screenBrightness = 0.0f;
myWindow.setAttributes(winParams);

and scheduling a Handler.postDelayed() to launch a Runnable in 1 sec to set the brightness back to full like this:

Window myWindow = getWindow();
WindowManager.LayoutParams winParams = myWindow.getAttributes();
winParams.screenBrightness = 1.0f;
myWindow.setAttributes(winParams);

However, the screen seems to be completely off and nothing happens after this 1 sec. Putting some trace into the Runnable clearly shows that it is launched by Handler.

I've also tried enclosing these two calls into a PARTIAL_WAKE_LOCK, with no result. Anyway, the Runnable works, so not much use of wake locks here.

Also, if the brightness set to 0.01f not to 0f, it works fine - after 1 sec it goes back to full.

Could anyone please advise how to make the brightness go back to full again after setting it to 0?

Using this code

params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);

does not turn the screen off, it makes the screen as dim as possible. Using the FLAG_KEEP_SCREEN_ON means that you will never allow the screen to go off and your device will go into low-power mode even if the particular device is allowing you to set the screen brightness to full-off .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM