开发者

Android: TelephonyManager.getSimSerialNumber() returns null

in which cases this method returns a null reference? Can only depend on the sim ca开发者_StackOverflow中文版rd? Doesn't exist, in these cases, an alternative to retrieve an identification number of the latter?

Thanks to all!


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


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


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

TelehponyManager manager = (TelehponyManager)getSystemService(TELEPHONY_SERVICE);

String imei = manager.getDeviceId();

String imsi = manager.getSubscriberId();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜