If your app needs to verify the password, we can use the system's Screenlock to authenticate, the advantage is that our users do not have to use a number of different passwords to verify identity, OK, let's look at how to use the System lock screen:
Let's introduce the lock screen related classes in several frameworks:
Lockpatternutils: Here are some of the help classes for the lock screen, which we need to use the 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 & amp;& savedpasswordexists (); return secure; }
This method is used to detect if the current system has used a lock screen.
Chooselockgeneric: This class is the main class where we set up the lock screen:
We call this class to guide the user 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 to do the lock screen verification, we can use such a 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 invoked activity to get the return value:
if (Requestcode = = && ResultCode = = ACTIVITY.RESULT_OK) {
55 is our request code.
With these methods, we can add validation to our app, adding system lock screen verification.
Above.
Protect your app with the system's own Screenlock