Search code examples
androidscreenlocking

Turning on screen programmatically


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?


Solution

  • 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();