Get SIM card status in Android phone

Source: Internet
Author: User
Public String Readsimcard () {
Telephonymanager TM = (Telephonymanager) this.getsystemservice (telephony_service)//access to related system services
StringBuffer sb = new StringBuffer ();
Switch (tm.getsimstate ()) {//getsimstate () Gets the status of the SIM with the following 6 status
Case TelephonyManager.SIM_STATE_ABSENT:sb.append ("no card");
Case TelephonyManager.SIM_STATE_UNKNOWN:sb.append ("Unknown state");
Case TelephonyManager.SIM_STATE_NETWORK_LOCKED:sb.append ("Need networkpin unlock");
Case TelephonyManager.SIM_STATE_PIN_REQUIRED:sb.append ("Need PIN unlocking");
Case TelephonyManager.SIM_STATE_PUK_REQUIRED:sb.append ("Need PUK unlock");
Case TelephonyManager.SIM_STATE_READY:sb.append ("good");
}

if (Tm.getsimserialnumber ()!=null) {
Sb.append ("@" + tm.getsimserialnumber (). toString ());
}else{
Sb.append ("@ cannot obtain SIM card number");
}

if (Tm.getsimoperator (). Equals ("")) {
Sb.append ("Cannot obtain supplier code");
}else{
Sb.append ("@" + tm.getsimoperator (). toString ());
}

if (Tm.getsimoperatorname (). Equals ("")) {
Sb.append ("Unable to obtain supplier");
}else{
Sb.append ("@" + tm.getsimoperatorname (). toString ());
}

if (Tm.getsimcountryiso (). Equals ("")) {
Sb.append ("@ Unable to acquire nationality");
}else{
Sb.append ("@" + tm.getsimcountryiso (). toString ());
}

if (Tm.getnetworkoperator (). Equals ("")) {
Sb.append ("@ Unable to obtain network operator");
} else {
Sb.append ("@" + tm.getnetworkoperator ());
}
if (Tm.getnetworkoperatorname (). Equals ("")) {
Sb.append ("@ Unable to obtain network operator name");
} else {
Sb.append ("@" + tm.getnetworkoperatorname ());
}
if (tm.getnetworktype () = = 0) {
Sb.append ("@ Cannot get network type");
} else {
Sb.append ("@" + tm.getnetworktype ());
}
return sb.tostring ();
}
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.