2
我寫下面的代碼來切換我的android手機的KeyGaurd
使用切換按鈕。但我面臨着一種奇怪的行爲。無法重新啓用KeyGaurd一旦禁用它
它成功禁用了
keygaurd
,但是。不能重新啓用。btnToggleLock.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (btnToggleLock.isChecked()) { toast.cancel(); toast.setText("Unlocked"); toast.show(); Log.i("Unlocked", "If"); KeyguardManager myKeyGuard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock myLock = myKeyGuard .newKeyguardLock(KEYGUARD_SERVICE); myLock.disableKeyguard(); } else { toast.cancel(); toast.setText("Locked"); toast.show(); KeyguardManager myKeyGuard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock myLock = myKeyGuard .newKeyguardLock(KEYGUARD_SERVICE); myLock.reenableKeyguard(); Log.i("Locked", "else"); } } });
它成功禁用了
keygaurd
,但是。不能重新啓用。- 我測試了它的控制是遍歷既
if
和以及else
也我米使用機器人2.2.1 motoralla milestone
。