Use built-in ScreenLock to protect your apps and screenlockapps

Source: Internet
Author: User

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.





Related Article

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.