Android mobile guard-bind SIM card serial number, androidsim

Source: Internet
Author: User

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:

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.