How can I get the ICCID number of the phone?
I looked in the TelephonyManager class, but didn't found there a way to get the ICCID number, there is only a method which tells if the ICC card is present.
The ICCID is the SIM card serial number. It's a unique 19 or 20 digit number that's usually printed on the plastic card that holds the SIM. The long sequence of numbers can be broken up to tell you more about the card.
Every SIM card has an ICCID number, which stands for Integrated Circuit Card Identifier and consists of 19 to 20 characters. Note: To make sure your device works properly, please confirm the correct SIM card is being used by matching the ICCID number associated with your device IMEI.
The ICCID is a globally unique serial number—a one-of-a-kind signature that identifies the SIM card itself. It stands for Integrated Circuit Card ID, a 19- or 20-digit number that's typically printed on the back of a SIM card.
It's best not to use this, as this is one of the identifiers that recently got restricted, just as was done recently on Android 10.
On Android 11 (API 30), even if you don't target it, you will most likely get just an empty string.
The recommendation of what to use is getSubscriptionId instead (requires READ_PHONE_STATE permission).
The reason:
Returns the ICC ID. Starting with API level 30, returns the ICC ID if the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission, has carrier privileges (see TelephonyManager#hasCarrierPrivileges), or is a device owner or profile owner that has been granted the READ_PHONE_STATE permission. The profile owner is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner access is deprecated and will be removed in a future release.
so it returns "the ICC ID, or an empty string if one of these requirements is not met" . For third party apps, this means you will probably always get an empty string.
If you don't meet these (and you usually don't), you can use it.
final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
And then for each of them, you can use subscriptionInfo.getIccId()
.
I believe getSimSerialNumber()
will get iccid.
UPDATE for Android 5.1 (credit Erick M Sprengel)
"Multiple SIM Card Support" was added for Android 5.1 (API 22).
Instead of using getSimSerialNumber
, you can use SubscriptionManager
.
SubscriptionManager sm = SubscriptionManager.from(mContext);
// it returns a list with a SubscriptionInfo instance for each simcard
// there is other methods to retrieve SubscriptionInfos (see [2])
List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();
// getting first SubscriptionInfo
SubscriptionInfo si = sis.get(0);
// getting iccId
String iccId = si.getIccId();
You will need the permission: (credit Damian)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With