How to show dialog even if the screen is locked?

后端 未结 2 1854
情深已故
情深已故 2020-12-15 14:19

I have implemented the push notification using GCM and when i receive the notification i want to show in a dialog for which i have created a custom dialog.

Now, i w

2条回答
  •  遥遥无期
    2020-12-15 14:37

    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.
    

    you should add this permission to manifest

    
    

    and this

    
    

提交回复
热议问题