Android-determine SIM card status

Source: Internet
Author: User

Android-determine SIM card status

Android determines the SIM card status and whether the SIM card is inserted.
For example, determine the preferred network type based on the SIM.

SIM card status

/*** Determine whether the SIM card is included ** @ return status */public static boolean hasSimCard () {Context context = App. getAppContext (); TelephonyManager telMgr = (TelephonyManager) context. getSystemService (Context. TELEPHONY_SERVICE); int simState = telMgr. getSimState (); boolean result = true; switch (simState) {case TelephonyManager. SIM_STATE_ABSENT: result = false; // No SIM card break; case TelephonyManager. SIM_STATE_UNKNOWN : Result = false; break;} Log. d (TAG, result? SIM card: No SIM card); return result ;}

All statuses

        TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);        int simState = telMgr.getSimState();        switch (simState) {            case TelephonyManager.SIM_STATE_ABSENT:                // do something                break;            case TelephonyManager.SIM_STATE_NETWORK_LOCKED:                // do something                break;            case TelephonyManager.SIM_STATE_PIN_REQUIRED:                // do something                break;            case TelephonyManager.SIM_STATE_PUK_REQUIRED:                // do something                break;            case TelephonyManager.SIM_STATE_READY:                // do something                break;            case TelephonyManager.SIM_STATE_UNKNOWN:                // do something                break;        }

 

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.