3

**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

thegreyspot
  • 4,079
  • 5
  • 28
  • 34
  • Try redrawing the views previously displayed, since with the last instruction actually is to turn on the backlights. Try invalidating (if possible) – Nikola Despotoski Jul 24 '11 at 03:34
  • Do you mind clarifying a bit? I tried googling redraw, but nothing clear came up :/ – thegreyspot Jul 24 '11 at 04:25
  • Last instruction you did is to turn the display on. Well, we presume that only does turning the backlights on, only white pixels on the screen, what I'm telling you is to redraw/invalidate the views you want to show, in other words the white pixels will be replaced. – Nikola Despotoski Jul 24 '11 at 04:28
  • yes but how do you redraw? I would have to redraw everything including the status bar at the top. – thegreyspot Jul 24 '11 at 04:30
  • http://developer.android.com/reference/android/os/PowerManager.html Read here this might be helpful i think. – Nikola Despotoski Jul 24 '11 at 04:33
  • I dont see anything about redraw in there :/ – thegreyspot Jul 24 '11 at 16:56
  • Indeed there is no about redrawing but there is how to turn on the screen – Nikola Despotoski Jul 24 '11 at 17:34
  • I am curious, have you tried setting the screen to 0.01 instead of 0, I had a similar problem and it solved it, seems like some mfg's don't like the zero setting. – Idistic Jul 30 '11 at 18:02

4 Answers4

2

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();
A. Abiri
  • 10,750
  • 4
  • 30
  • 31
1

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)

pandre
  • 6,685
  • 7
  • 42
  • 50
1

The best way to get this to work is to us the PowerManager.goToSleep(time);

That way you can control (if you wish) how long you want the device to sleep for, you can also use PowerManager.isScreenOn() to determine if it has been switched on again.

You will have to setup the WakeLock if your already haven't...quite easy just do

PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");  

and from that you can use powerManager.goToSleep

EDIT

make sure you release the WakeLock and acquire them on your onPause and onResume methods!

Idistic
  • 6,281
  • 2
  • 28
  • 38
Chris
  • 1,766
  • 1
  • 21
  • 36
0

Screen brightness ranges from 0 to 1, while the -1 you're using is for "preferred" brightness. First try using 1 and see if that works, as -1 may just be keeping what it was previously set to.

Izkata
  • 8,961
  • 2
  • 40
  • 50