Reputation: 193
this question have no answer till now ??? In my application I disable the keyguard lock (i.e.Remove Lockscreen) using the code below and it works fine until I click on any notification in the notification bar. If I click on a notification the lock screen is automatically re-enabled. Any help is appreciated.
private void remove_lockscreen() {
final CheckBoxPreference lock = (CheckBoxPreference) findPreference("remove_lockscreen");
KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock kl = km.newKeyguardLock("keyguard_lock");
if (lock.isChecked()) {
prefEdit("remove_lockscreen", 1);
Toast.makeText(getBaseContext(), "Lockscreen will not be shown", Toast.LENGTH_SHORT).show();
kl.disableKeyguard();
}
else if (!lock.isChecked()) {
prefEdit("remove_lockscreen", 0);
Toast.makeText(getBaseContext(), "Lockscreen will be shown", Toast.LENGTH_SHORT).show();
kl.reenableKeyguard();
android.os.Process.killProcess(android.os.Process.myPid());
}
}
and i used this code Disabled Keyguard Lock re-enables itself after clicking on a notification but never work !!?? any help
Upvotes: 0
Views: 2999
Reputation: 1444
KeyguardLock API was deprecated from Android API level 13 :http://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html
You are trying this on Note 4 device, which has Android API level greater than 13. Therefore, it will now work.
Try this for issue 1:
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
this.getWindow().setType(WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
this.getWindow().setType(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Issue 2: Lock is re-enabled on clicking a notification- this is because on clicking a notification a new app is launched and your app is sent to the background. Thus, it looses the control over Lock which was disabled by it and lock is re-enabled by the system. Are you calling finish() in your app?
Upvotes: 1