Reading SIM Details

If your application is running on a GSM device it will have a SIM. You can query the SIM details from the Telephony Manager to obtain the ISO country code, operator name, and operator MCC (mobile country code) and MNC (mobile network code) for the SIM installed in the current device. These details can be useful if you need to provide specialized functionality for a particular carrier.

You can also obtain the serial number for the current SIM if you include the read_phone_state uses-permission in your application manifest.

Before you can use any of these methods you must ensure that the SIM is in a ready state. You can determine this using the getSimState method as shown in Listing 12-6.

TING 12-6: Reading SIM details int simState = telephonyManager.getSimState(); switch (simState) {

case (TelephonyManager.SIM_STATE_ABSENT): break; case (TelephonyManager.SIM_STATE_NETWORK_LOCKED): break; case (TelephonyManager.SIM_STATE_PIN_REQUIRED): break; case (TelephonyManager.SIM_STATE_PUK_REQUIRED): break; case (TelephonyManager.SIM_STATE_UNKNOWN): break; case (TelephonyManager.SIM_STATE_READY): { // Get the SIM country ISO code

String simCountry = telephonyManager.getSimCountryIso(); // Get the operator code of the active SIM (MCC + MNC) String simOperatorCode = telephonyManager.getSimOperator(); // Get the name of the SIM operator

String simOperatorName = telephonyManager.getSimOperatorName(); // -- Requires READ_PHONE_STATE uses-permission --// Get the SIM's serial number

String simSerial = telephonyManager.getSimSerialNumber();

Available for download on Wrox.com break;

default: break;

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment