Android and androidsdk
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? "With SIM card": "Without 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; }
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.