How can I get the ICCID number of the phone?

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" />

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() .

Tags:

Android