Recently, I have been looking for reliable ways to control a secured Android Keyguard. Mainly to display a custom lock screen. I know that Google had state
If AOSP is in your control then you need to set the simple flag and keyguard() is gone for good. Here is the details to do that, get into the file "overlay/frameworks/base/packages/SystemUI/res/values/config.xml" and search for "config_enableKeyguardService" then set the flag to false.
NO MORE keyGuard, pheww
I have used this with some success in both Gingerbread and ICS to open my activity (via a background service which is starting it). In the activity being started:
@Override
public void onAttachedToWindow() {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
In your LockScreenActivity, ending the validation code by finish();
kills the LockscreenActivity and thus the whole app. Instead of that, you could just launch back your main activity (or any other) like this :
startActivity(new Intent(LockScreenActivity.this, MainActivity.class));
I had the same problem for the click of HOME button while unlocking the device. This can be solved by reseting the password to blank (ie "") :
DevicePolicyManager devicePolicyManager;
ComponentName demoDeviceAdmin;
devicePolicyManager.setPasswordQuality(demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 0);
devicePolicyManager.resetPassword("",DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
and then disabling the keygaurd :
this.keyGuardLock = ((KeyguardManager)getSystemService("keyguard")).newKeyguardLock("keyguard");
keyGuardLock.disableKeyguard();
Hope this solved your problem. \m/ keep coding!
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED allows an activity(a window) to be displayed on screen on, putting the Keyguard behind
I tried to get this but my activity always preceded by the system lock screen. isOrderdBroadcast() says that ACTION_SCREEN_NO is an ordered broadcast.
I added flag to the activity :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
in onAttachedView(). But still the system lock is getting the preference over my Custom screen lock activity.
How did you get your activity before the system lock screen?
EDIT On a hindsight, I think my understanding of the lock screen concept was wrong. My broadcast receiver was getting the broadcast first. But what was showing before that was the system lock screen launched when SCREEN_OFF is received. Fixed that problem as of now.
But stumped by the ambiguity of home button behavior. This won't be a problem in post ICS devices as all hard buttons are discouraged.