Obtaining SIM Serial Number in Android 13

653 views Asked by At

I'm trying to retrieve the SIM serial number (also known as ICCID) in Android 13 using the TelephonyManager and SubscriptionManager, but I'm encountering some issues. Here's what I've tried:

  1. I've declared the necessary permissions in my AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

2.I'm using the following code to get the SIM serial number:

TelephonyManager telephonyManager = getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
    SubscriptionManager subscriptionManager = getSystemService(SubscriptionManager.class);
    List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    
    if (subscriptionInfoList != null) {
        for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
            String simSerialNumber = subscriptionInfo.getIccId();
            // Handle the SIM serial number here
        }
    }
}

However, this code doesn't seem to be working in Android 13. It used to work in earlier versions, but it's not retrieving the SIM serial number.

Are there any alternative methods to retrieve the SIM serial number in Android 13? Any help or guidance on this issue would be greatly appreciated. Thank you!

1

There are 1 answers

1
404NotFound On

Most of the times it gives empty string only: this is what official document says Link

Returns the ICC ID. Starting with API level 29 Security Patch 2021-04-05, > 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.