Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank screen when restoring screenBrightness Android

**Please note, Im just trying to turn off the display. If you have better method of doing this please suggest it :)

I am using

params.screenBrightness = 0;
getWindow().setAttributes(params);

and

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

to turn on/off the display. When I turn the screen back on, all I get is a blank screen with the backlight on.

Any idea why this is happening? Thank you Mike

like image 284
thegreyspot Avatar asked Jan 23 '26 10:01

thegreyspot


2 Answers

Though a minor change, try putting an "F" at the end like this:

params.screenBrightness = 0F;
getWindow().setAttributes(params);

If that doesn't work in fixing the problem, maybe refreshing the screen might work by bringing back the screen to its default settings. I did a little research and found this code that might work in refreshing the screen:

this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

Also, you could try turning on the phone with the powermanager wakelock:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Wakes the screen on.
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, AudioControlExtender.this.getClass().getName());
wl.acquire();

And if that doesn't work, then turn on the screen the way you are doing right now and then do this:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Sets the screen on maximum brightness.
// This might fix the problem you are having with the screen brightness since
// the screen settings are changed.
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, AudioControlExtender.this.getClass().getName());
wl.acquire();
like image 100
A. Abiri Avatar answered Jan 24 '26 23:01

A. Abiri


If you are trying to turn off display, have you tried
PowerManager.goToSleep() ?
Check more info at http://developer.android.com/reference/android/os/PowerManager.html#goToSleep(long)

like image 40
pandre Avatar answered Jan 24 '26 22:01

pandre