Turning on screen programmatically

前端 未结 5 822
情话喂你
情话喂你 2020-11-29 07:23

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.newKeyguardL         


        
5条回答
  •  生来不讨喜
    2020-11-29 08:00

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

提交回复
热议问题