Android phone defender's binding SIM card serial number _android

Source: Internet
Author: User

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

Here you need to implement the ability to bind the SIM card serial number, and note that the appropriate permissions are added: 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 state, used 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. The original state is//5 and the state is set to the current entry Siv_sim_bound.setcheck (!ischeck); 6, storage (sequence card number)//6.1 get the SIM card serial number Telephonemanager if (!ischeck) {Telephonymanager manager = (Telephony MansAger) Getsystemservice (Context.telephony_service);
          6.2 Get the SIM card serial card number String Simserialnumber = Manager.getsimserialnumber ();
        6.3 Storage sputil.putstring (Getapplicationcontext (), Constantvalue.sim_number, Simserialnumber);
        else {//7, the node that will store the serial card number, remove the sputil.remove from the SP (Getapplicationcontext (), constantvalue.sim_number);
  }
      }
    });

 }

Add Remove method in Sputil

  /**
   * Remove specified node from SP *
   @param  Context Environment
   * @param key    requires a node name/public
  static void Remove (context context, String key) {
    //(Storage node file name, read/write)
    if (sp = null) {
      SP = context.getsharedpreferences ("config", context.) mode_private);
    }
    Sp.edit (). Remove (key). commit ();
  }

Run the project, check the checkbox, and view the Config.xml file under the Data/data..../shared_prefs file, which reads 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>

Indicates that the function of the binding 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 the toast reminder, the logical 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, "Please bind SIM card");
    }
  

The effect of the following figure:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.