Question

In versions of android before 4.2 I used to have some code to flash the screen on when a notification came into the app (if users wanted it to flash). I used:

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(
                     PowerManager.SCREEN_DIM_WAKE_LOCK | 
                     PowerManager.ACQUIRE_CAUSES_WAKEUP, "example_tag"
                                         );
wl.acquire();

//this would switch the screen on
//then after a little while I'd call
wl.release(); 

So the "aquire" method would switch the screen on (if it wasn't already) and the "release" would switch it straight back off.

In android 4.2 it seems that the switching off doesn't happen when you release the wakelock, but only when the screen timeout setting for the display is reached (default seems to be 2 minutes)

Is there any way to make it switch off when the wakelock is released. I've seen some bits in the API about specifically switching the screen on and off, but I'm a little unsure about using as I wouldn't want the app switching the screen off if somebody was in the middle of doing something, so the wakelock seemed to work well. Any suggestions?

Was it helpful?

Solution

The only way I've found it to set the screen timeout down to a short time but store off the default and restore it when finished. This will turn it down to around 5-7 seconds at the shortest and you have to be careful to restore the setting back correctly afterwards as it's a total hack really.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top