Use built-in ScreenLock to protect your apps and screenlockapps
If your App needs to verify the password, we can use the system ScreenLock for verification. The advantage of this is that our users do not have to use multiple passwords to verify their identities. OK, let's take a look at how to use the system lock screen:
First, we will introduce several lock-related classes in the Framework:
LockPatternUtils: Some help classes for lock screen are provided here. We need to use this method most:
public boolean isSecure() { long mode = getKeyguardStoredPasswordQuality(); final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC || mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC || mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; final boolean secure = isPattern && isLockPatternEnabled() && savedPatternExists() || isPassword && savedPasswordExists(); return secure; }
This method is used to check whether the current system has used the lock screen.
ChooseLockGeneric: this class is the main class for setting the screen lock:
We call this class to guide users to add a system lock screen:
Intent intent = new Intent("/"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ComponentName cm = new ComponentName("com.android.settings","com.android.settings.ChooseLockGenericForKS"); intent.setComponent(cm); startActivity(intent);
So how can we verify the lock screen? We can use this method:
private boolean runKeyguardConfirmation(int request) { Resources res = getActivity().getResources(); return new ChooseLockSettingsHelper(getActivity(), this) .launchConfirmationActivity(request, res.getText(R.string.master_clear_gesture_prompt), res.getText(R.string.master_clear_gesture_explanation)); }
We need to use onActivityResult in the called Activity to obtain the returned value:
if (requestCode == 55 && resultCode == Activity.RESULT_OK) {
55 is our request code.
Through the above method, we can add verification in our App, and add the system lock screen verification.
Above.