how to show popup Activity or Dialog when phone is locked?

前端 未结 3 1776
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 04:36

I am trying to show a activity or a dialog when the phone is locked. I have tried using a WakeLock but it did not work and I can only see the activity once my phone is unloc

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 05:25

    You should use the KeyGuardManager to unlock the device automatically and then acquire your Wake Lock.

        KeyguardManager kgm = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
        boolean isKeyguardUp = kgm.inKeyguardRestrictedInputMode();
        KeyguardLock kgl = kgm.newKeyguardLock("Your Activity/Service name");
    
        if(isKeyguardUp){
        kgl.disableKeyguard();
        isKeyguardUp = false;
        }
    
        wl.acquire(); //use your wake lock once keyguard is down.
    

提交回复
热议问题