Turning on screen programmatically

Matroska picture Matroska · May 23, 2010 · Viewed 34.6k times · Source

I would like to unlock screen and switching it on to show a popup on an event trigger. I am able to unlock the screen using

newKeyguardLock = km.newKeyguardLock(HANDSFREE);
newKeyguardLock.disableKeyguard();

on KeyGuardService but I cannot turn on the screen. I am using

wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, HANDSFREE);
wl.acquire();

but with no success. The screen still remains off. How can I achieve this?

Answer

undefined picture undefined · Apr 19, 2012

Note from author: I wrote this back in 2012. I don't know if it works anymore. Be sure to check out the other more recent answers.


Amir's answer got me close, but you need the ACQUIRE_CAUSES_WAKEUP flag at least (Building against Android 2.3.3).

WakeLock screenLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(
     PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
screenLock.acquire();

//later
screenLock.release();