Protect your app with the system's own Screenlock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.