0

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

Community
  • 1
  • 1
user3623824
  • 193
  • 3
  • 13

1 Answers1

1

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?

abhi
  • 1,412
  • 19
  • 25
  • sure . i know that is deprecated .. but how can disable keyguard, i try use flag wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON); .. but not work – user3623824 Dec 28 '14 at 13:18
  • please look to this solution http://stackoverflow.com/questions/13052470/disabled-keyguard-lock-re-enables-itself-after-clicking-on-a-notification/14519861#14519861 – user3623824 Dec 28 '14 at 13:21
  • Can you please tell us in detail what are you trying to achieve, I mean what is the objective? – abhi Dec 28 '14 at 13:28
  • 1- disable keyguard way that can work with any device? .. my app will disable keyguard when at specific time and will open activity .. this action work with some devices and other not work 2- second issue after disable keyduard when click any notification keyguard re-enable itself .. any suggest ?? – user3623824 Dec 28 '14 at 13:34
  • thank u for ur great help .. 1- i put this code in onResume method but still not disable keyguard 2- second issue .. yes i call finish in my app – user3623824 Dec 28 '14 at 13:56