tags:

views:

33

answers:

1

Hi, 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 unlocked?

What is the proper way to do this?

+1  A: 

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

    KeyguardManager kgm = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
    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.
Donal Rafferty
Thankyou that works
Jason