我試圖在我的應用程序中爲用戶創建選項(使用複選框首選項)以禁用並重新啓用鎖定屏幕。我使用disableKeyguard()來禁用鎖定屏幕,它的工作原理完美無瑕,但我無法使reenableKeyguard()正常工作。代碼非常簡單,我不知道爲什麼它不起作用。Android:禁用後無法重新啓用鍵盤保護程序
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();
}
}
您是否找到了解決方案?我有同樣的問題。 –
@QadirHussain是,發佈了下面的答案。 –