Saturday, October 9, 2010

How to identify when lock screen is unlocked.?

My requirement was to listen for the intent when the screen is unlocked successfully.
Unfortunately, there is no such intent defined by Android framework, when the screen is unlocked successfully.

So i went into the framework code which takes care of showing lock screen, unlock screen and handling the events on that. It is present

If in case you are working in framework level code and looking for the exact place in the code, here it is.

Line no 801:
Here i have written code, to notify the Notification service, when the screen is unlocked. It works fine.

public void keyguardDone(boolean authenticated, boolean wakeup) {
synchronized (this) {
EventLog.writeEvent(70000, 2);
if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")");
System.out.println("Keygaurd screen unlocked ");
mManager.notify("SCREEN_UNLOCKED"); // The code i added.
Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
msg.arg1 = wakeup ? 1 : 0;

if (authenticated) {

if (mExitSecureCallback != null) {
mExitSecureCallback = null;

if (authenticated) {
// after succesfully exiting securely, no need to reshow
// the keyguard when they've released the lock
mExternallyEnabled = true;
mNeedToReshowWhenReenabled = false;

There are intents for when the screen is ON & OFF, but you can use that for screen unlocking.


I found in one of the forums which suggesting in round other way.

- (After screen is on,) Wait for ACTION_MAIN with category CATEGORY_HOME (Which launches the home screen) - This is probably what is sent after the phone gets unlocked.

Not sure this works. !! Check it out.

No comments:

Post a Comment