Android mobile guard-bind SIM card serial number, androidsim
Now let's take a look at the logic of each navigation page. First, let's look at the second navigation page.
For more information, see http://www.cnblogs.com/wuyudong/p/5949775.html.
You need to bind the serial number of the SIM card. Add the corresponding permission: uses-permission android: name = "android. permission. READ_PHONE_STATE"
Private SettingItemView siv_sim_bound; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_setup2); initUI ();} private void initUI () {siv_sim_bound = (SettingItemView) findViewById (R. id. siv_sim_bound); // 1. echo (read the existing binding status to show whether the serial number of the SIM card is stored in the sp) final String sim_number = SpUtil. getString (this, ConstantValue. SIM_NUMBER ,""); // 2. determine whether the sequence card number is "" if (TextUtils. isEmpty (sim_number) {siv_sim_bound.setCheck (false);} else {siv_sim_bound.setCheck (true);} siv_sim_bound.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {// 3. obtain the original method boolean isCheck = siv_sim_bound.isCheck (); // 4. reverse the original status // 5, and set the status to the current entry siv_sim_bound.setCheck (! IsCheck); // 6, storage (Serial card number) // 6.1 get SIM card serial number TelephoneManager if (! IsCheck) {TelephonyManager manager = (TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE); // 6.2 gets the serial card number of the SIM card String simSerialNumber = manager. getSimSerialNumber (); // 6.3 stores SpUtil. putString (getApplicationContext (), ConstantValue. SIM_NUMBER, simSerialNumber);} else {// 7, delete the node storing the serial card number from the sp. remove (getApplicationContext (), ConstantValue. SIM_NUMBER );}}});}
Add the remove Method to SpUtil.
/*** Remove a specified node from the sp * @ param context Context * @ param key requires the name of a node */public static void remove (context, String key) {// (storage node file name, read/write mode) if (sp = null) {sp = context. getSharedPreferences ("config", context. MODE_PRIVATE);} sp. edit (). remove (key ). commit ();}
Run the project, check the checkbox option, and view the config. xml file under the data/data.../shared_prefs file. The content is as follows:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?><map> <string name="mobile_safe_psd">1107f203c8f0cd474aa3ab6a6e03c6cc</string> <string name="sim_number">89014103211118510720</string></map>
It indicates that the SIM card binding function has been implemented.
When the checkbox is not selected, that is, the SIM card is not selected. When you click "next page", a toast reminder will pop up. The logic code is as follows:
Public void nextPage (View view) {String serialNumber = SpUtil. getString (this, ConstantValue. SIM_NUMBER, ""); if (! TextUtils. isEmpty (serialNumber) {Intent intent = new Intent (getApplicationContext (), Setup3Activity. class); startActivity (intent); finish () ;}else {ToastUtil. show (this, "bind SIM card ");}}
The effect is as follows: