Android: You can’t unlock the keypad after unlocking it.

I am trying to create an option (using the checkbox settings) in my application so that the user can turn the lock screen off and on again. I use disableKeyguard () to disable the lock screen and it works flawlessly, but I cannot get reenableKeyguard () to work. The code is pretty simple, I do not know why it does not work.

public void onSharedPreferenceChanged(SharedPreferences taskprefs,
        String tasks_pref) {
    boolean skiplock = taskprefs.getBoolean("pref_skiplock", false);
    boolean screentimeout = taskprefs.getBoolean("pref_screentimeout",
            false);

    skiplock(skiplock);

    // Log.v("TaskActivity", "Skiplock value is " + skiplock);
    // Log.v("TaskActivity", "ScreenTimeout value is " + screentimeout);
}

private void skiplock(boolean action) {
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    //
    if (action == true) {
        lock.disableKeyguard();
        Toast.makeText(getApplicationContext(), "Lockscreen Disabled",
                Toast.LENGTH_SHORT).show();
    }
    //
    else if (action==false) {
        lock.reenableKeyguard();
        Toast.makeText(getApplicationContext(), "Lockscreen Enabled",
                Toast.LENGTH_SHORT).show();
    }
}
+3
source share
1 answer

, Keyguard () skiplock() , . - keyguard , reset, .

, " KeguardLock" "KeyguardManager keyguardManager" .

+4

All Articles