如何在 Android 中获取双卡 IMEI 号

How to get dual sim IMEI no in Android

我必须在 android phone 上找到双 SIM 卡 imei 号码。我检查了很多网站,发现我必须使用 getdeviceid(0) or getdeviceid(1) 但它不起作用。它显示错误

密码是

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

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

我附上了截图。请查看并回复我

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

它只适用于API 22 级及以上

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();
            }
        }