I am writing below code to switch KeyGaurdmy Android phone using the toggle button. but I came across strange behavior.
KeyGaurd
It successfully disables KeyGaurd, but. not re-enable.
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"); } } });
if
else
I also use android 2.2.1 motoralla milestone.
motoralla milestone
, Lock (KeyGuardLock) , if. , " " , , .
, onClickListener. .. "if" onClickListener: -
KeyguardManager myKeyGuard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock myLock = myKeyGuard .newKeyguardLock(KEYGUARD_SERVICE);