Android determines the phone SIM status

Source: Internet
Author: User

Android determines the phone SIM status
Public String readSIMCard (){
TelephonyManager tm = (TelephonyManager) this. getSystemService (TELEPHONY_SERVICE); // obtain related system services
StringBuffer sb = new StringBuffer ();
Switch (tm. getSimState () {// getSimState () gets the sim in the following 6 states:
Case TelephonyManager. SIM_STATE_ABSENT: sb. append ("no card"); break;
Case TelephonyManager. SIM_STATE_UNKNOWN: sb. append ("unknown state"); break;
Case TelephonyManager. SIM_STATE_NETWORK_LOCKED: sb. append ("NetworkPIN unlock required"); break;
Case TelephonyManager. SIM_STATE_PIN_REQUIRED: sb. append ("PIN unlock required"); break;
Case TelephonyManager. SIM_STATE_PUK_REQUIRED: sb. append ("requires PUK unlock"); break;
Case TelephonyManager. SIM_STATE_READY: sb. append ("good"); break;
}

If (tm. getSimSerialNumber ()! = Null ){
Sb. append ("@" + tm. getSimSerialNumber (). toString ());
} Else {
Sb. append ("@ cannot get SIM card number ");
}

If (tm. getSimOperator (). equals ("")){
Sb. append ("@ unable to 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 get network operator name ");
} Else {
Sb. append ("@" + tm. getNetworkOperatorName ());
}
If (tm. getNetworkType () = 0 ){
Sb. append ("@ unable to obtain 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.