Android mobile guard-whether there is a password to distinguish the dialog box type, android guard

Source: Internet
Author: User

Android mobile guard-whether there is a password to distinguish the dialog box type, android guard

This article begins to gradually implement the "Mobile Phone anti-theft" function module of the configuration center.

URL:/www.cnblogs.com/wuyudong/p/5939123.html.

Click "mobile anti-theft". If no password has been set before, the following dialog box is displayed:

If you have set a password, the following dialog box is displayed:

You can use SharedPreferences to store the Saved Password status.

Add the following code to the previously created SpUtil class:

// Write/*** write the String variable to the sp * @ param context * @ param key storage node name * @ param value storage node value String */public static void putString (Context context, string key, String value) {// (storage node file name, read/write mode) if (sp = null) {sp = context. getSharedPreferences ("config", context. MODE_PRIVATE);} sp. edit (). putString (key, value ). commit ();} /*** read String from sp * @ param context * @ param key storage node name * @ param defValue storage node default value * @ return default value or the result read by this node */public static String getString (Context context, string key, String defValue) {// (storage node file name, read/write mode) if (sp = null) {sp = context. getSharedPreferences ("config", context. MODE_PRIVATE);} return sp. getString (key, defValue );}

In this way, when you click the mouse, you can listen to the click event to add the judgment logic.

Private void showDialog () {// determines whether the local storage password (sp String) String psd = SpUtil. getString (this, ConstantValue. MOBILE_SAFE_PSD, ""); if (TextUtils. isEmpty (psd) {// 1. initial password Setting Dialog Box showSetPsdDialog ();} else {// 2. Confirm the Password dialog box showConfirmPsdDialog ();}} /*** Confirm Password dialog box */private void showConfirmPsdDialog () {}/ *** SET Password dialog box */private void showSetPsdDialog (){}

MOBILE_SAFE_PSD is a constant in the ConstantValue class.

Package com. wuyudong. mobilesafe. utils;/*** Created by wuyudong on 2016/10/6. */public class ConstantValue {/*** whether to enable the update key */public static final String OPEN_UPDATE = "open_update "; /*** SET Password key */public static final String MOBILE_SAFE_PSD = "mobile_safe_psd ";}

The following code is added to the showConfirmPsdDialog and showSetPsdDialog methods.

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.