Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable Keyguard and display an activity to the user when receiver of SCREEN_ON is triggered?

How can I disable the keyguard when a broadcast receiver is activated by screen_on, so that when it occurs the user sees an activity that I have started behind it? (The activity is running already...)

I have been trying the following code from a broadcast receiver triggered by screen off...

KeyguardManager  myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
myLock = myKeyGuard.newKeyguardLock();
myLock.disableKeyguard();

It doesn't seem to be working though as it is. When I turn the screen on, I still have to manually unlock the keyguard on the phone to reveal the activity behind it.

like image 383
Ryan Avatar asked Nov 20 '10 18:11

Ryan


2 Answers

i would recommend using the window flags dismiss_keyguard or show_when_locked if you have a window that needs to come over the top of the lockscreen right at wakeup.

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SHOW_WHEN_LOCKED

how you use this is as follows (called in onCreate before setting layout)

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
like image 68
mylock Avatar answered Oct 17 '22 22:10

mylock


I think I figured out what I did wrong. It seems like it was just a tag error in my manifest when using the disable_keyguard permission. It's working correctly now that I corrected the manifest.

like image 31
Ryan Avatar answered Oct 17 '22 21:10

Ryan