简体   繁体   中英

How to get dual sim IMEI no in Android

I have to find dual sim imei number on my android phone . I have check on many website I found that I have to use getdeviceid(0) or getdeviceid(1) But its not working . It showing the error

The code is

TelephonyManager   telephonyManager  =
                    (TelephonyManager)getSystemService( Context.TELEPHONY_SERVICE );

            String imei = telephonyManager.getDeviceId(0);
            String imei1 = telephonyManager.getDeviceId(1);

I have attached the screenshot . Kindly check it and reply me

在此处输入图片说明

 TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
 String m1PhoneNumber = tMgr.getLine1Number();
 String m2PhoneNumber = tMgr.getLine2Number();


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

its only worked in API Level 22 and above

if (android.os.Build.VERSION.SDK_INT >= 22) {
            try {
                TelephonyManager telephonyManager = (TelephonyManager)
                        getSystemService(Context.TELEPHONY_SERVICE);
                SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
                int Count = subscriptionManager.getActiveSubscriptionInfoCount();
                if (telephonyManager != null) {

                    if (Count > 1) {
                        if (android.os.Build.VERSION.SDK_INT >= 22) {
                            SIM1 = telephonyManager.getDeviceId(0);
                            SIM2 = telephonyManager.getDeviceId(1);

                            if (!SIM1.equalsIgnoreCase("") && !SIM2.equalsIgnoreCase("")) {
                                isDualSIM = true;
                            }

                        }
                    }else{
                        // single sim
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM