Android phone defender--bind SIM card serial number

Source: Internet
Author: User

Now start to deal with the logic of each navigation page, first look at the second navigation page

This article address: http://www.cnblogs.com/wuyudong/p/5949775.html, reprint please indicate the source.

There is a need to implement the ability to bind the SIM card serial number, note that the appropriate permissions are added: Uses-permission android:name= "Android.permission.READ_PHONE_STATE"

   PrivateSettingitemview Siv_sim_bound; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_SETUP2);    Initui (); }    Private voidInitui () {Siv_sim_bound=(Settingitemview) Findviewbyid (R.id.siv_sim_bound); //1. Echo (read the existing binding state and use it as the serial number that shows whether the SIM card is stored in the SP)        FinalString Sim_number = sputil.getstring ( This, Constantvalue.sim_number, ""); //2. Determine if the serial card number is ""        if(Textutils.isempty (Sim_number)) {Siv_sim_bound.setcheck (false); } Else{Siv_sim_bound.setcheck (true); } siv_sim_bound.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {//3. Get the original method                BooleanIscheck =Siv_sim_bound.ischeck (); //4. Reverse the original state//5, Status set to current entrySiv_sim_bound.setcheck (!Ischeck); //6, Storage (serial card number)//6.1 Get the SIM card serial number Telephonemanager                if(!Ischeck) { Telephonymanager manager = (Telephonymanager) Getsystemservice (context.telephony_service);                     //6.2 Get the serial card number of the SIM cardString Simserialnumber =Manager.getsimserialnumber ();                    //6.3 Storagesputil.putstring (Getapplicationcontext (), Constantvalue.sim_number, Simserialnumber); } Else {                    //7, remove the node that stores the serial card number from the SP sputil.remove(Getapplicationcontext (), constantvalue.sim_number);    }            }        }); }                  

Add the Remove method to the Sputil

    /*** Removes the specified node from the SP *@paramContext Environment *@paramkey requires the name of a node*/     Public Static voidRemove (context 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 (); }

To run the project, check the checkbox to view the CONFIG. data/data..../shared_prefs file under the following section:

<?XML version= ' 1.0 ' encoding= ' utf-8 ' standalone= ' yes '?><Map>    <stringname= "MOBILE_SAFE_PSD">1107f203c8f0cd474aa3ab6a6e03c6cc</string>   <string  name= "Sim_number">89014103211118510720</  string>   </Map>

Description of the ability to bind the SIM card has been implemented

When the checkbox is not selected, that is, the SIM card is not selected, this time click on the "Next page" will pop up a toast reminder, the logic code is as follows:

     Public void nextPage (view view) {        = sputil.getstring (This, Constantvalue.sim_number, "");         if (! Textutils.isempty (serialnumber)) {            new Intent (Getapplicationcontext (), setup3activity.  Class);            StartActivity (intent);            Finish ();         Else {            toastutil.show (This, "Please bind SIM card");        }    } 

Android phone defender--bind SIM card serial number

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.