**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
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();
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With