0

I want to check that user device is dual sim or not. I have a TelephonyInfo class. its getInstance method of this class:

public static TelephonyInfo getInstance(Context context) {

        if (telephonyInfo == null) {

            telephonyInfo = new TelephonyInfo();

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

            telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();
            telephonyInfo.imeiSIM2 = null;

            try {
                telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
                telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
            } catch (GeminiMethodNotFoundException e) {
                e.printStackTrace();

                try {
                    telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
                    telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();

                    try {
                        telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdDs", 0);
                        telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdDs", 1);
                    } catch (GeminiMethodNotFoundException e2) {
                        //Call here for next manufacturer's predicted method name if you wish
                        e2.printStackTrace();
                    }
                }
            }

            try {
                telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorNameGemini", 0);
                telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorNameGemini", 1);
            } catch (GeminiMethodNotFoundException e) {
                e.printStackTrace();

                try {
                    telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorName", 0);
                    telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorName", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();

                    try {
                        telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorNameDs", 0);
                        telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorNameDs", 1);
                    } catch (GeminiMethodNotFoundException e2) {
                        //Call here for next manufacturer's predicted method name if you wish
                        e2.printStackTrace();
                    }
                }
            }

            telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
            telephonyInfo.isSIM2Ready = false;

            try {
                telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
                telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
            } catch (GeminiMethodNotFoundException e) {

                e.printStackTrace();

                try {
                    telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
                    telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();
                }
            }
        }

        return telephonyInfo;
    }  

And i check device stat with this method :

public boolean isDualSIM() {
        return imeiSIM2 != null;
    }

And finally i use this class in this way :

TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(mActivity);
isDualSimCard = telephonyInfo.isDualSIM();

Im using Sony experia z2 with android 5.1.1 , this device is not dual sim but isDualSim() method return true.
What is wrong in my code ?

YFeizi
  • 1,498
  • 3
  • 28
  • 50

0 Answers0