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.