Skip to content Skip to sidebar Skip to footer

Android: TelephonyManager.getSimSerialNumber() Returns Null

in which cases this method returns a null reference? Can only depend on the sim card? Doesn't exist, in these cases, an alternative to retrieve an identification number of the latt

Solution 1:

Please make sure whether you have added the following permission in the Android Manifest, if not please add this statement add try again.

<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

Note: Add this permission tag outside the application tag..

Sample Snippet:

.....
.....
.....
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android......"/>
 ..........
 </manifest>

All the Best


Solution 2:

try the below code..i will help full for u..

TelehponyManager manager = (TelehponyManager)getSystemService(TELEPHONY_SERVICE);

String imei = manager.getDeviceId();

String imsi = manager.getSubscriberId();

Solution 3:

getSimSerialNumber() needs privileged permissions from Android 10 onwards, and third party apps can't register this permission.

See : https://developer.android.com/about/versions/10/privacy/changes#non-resettable-device-ids

A possible solution is to use the TELEPHONY_SUBSCRIPTION_SERVICE from Android 5.1, to retrieve the sim serial number. Steps below:

  • Check for READ_PHONE_STATE permission.
  • Get Active subscription list.( Returns the list of all active sim cards)
  • Retrieve the sim details from Subscription Object.

    if ( isPermissionGranted(READ_PHONE_STATE) ) {

            String simSerialNo="";
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
    
                SubscriptionManager subsManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); 
    
                List<SubscriptionInfo> subsList = subsManager.getActiveSubscriptionInfoList();
    
                if (subsList!=null) {
                    for (SubscriptionInfo subsInfo : subsList) {
                        if (subsInfo != null) {
                            simSerialNo  = subsInfo.getIccId());
                        }
                    }
                }
            } else {
                TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                simSerialNo = tMgr.getSimSerialNumber();
            }
        }
    

Check if this helps


Post a Comment for "Android: TelephonyManager.getSimSerialNumber() Returns Null"