Android 5.0 Lollipop dismiss secure lock keyguard

2.4k views Asked by At

I have an activity that is correctly shown in front of the keyboard when an alarm goes off. Everything works fine, I set the following flags:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Now, inside my app I have a link to Instagram, and I want to open the Instagram app without asking the user to unlock his device (if he uses the secure lock). Using the flags above it doesn't work, I was able to achieve my aim by using:

    KeyguardManager manager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock lock = manager.newKeyguardLock("abc");
    lock.disableKeyguard();

but after that, I can't lock my device again. Do you have any suggestion? Or alternatively Is there any Intent flag or property that I can use in order to open Instagram app in front of the lock screen?

Many Thanks

1

There are 1 answers

0
marmor On

When done, call lock.reenableKeyguard();