2

I am trying to get a list of networks on Android devices that have multiple SIM cards "dual sim."

I use the TelephonyManager class but the method getNetworkType only returns the network for the first sim "sim 1."

Jake Chasan
  • 6,290
  • 9
  • 44
  • 90
efr
  • 301
  • 3
  • 10

2 Answers2

0

There's no API for this before Android Android 5.1 (API22). But then you have SubscriptionManager and its getActiveSubscriptionInfoList()

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Thanks for your answer, but the problem with the SubscriptionManager is that not return network of each sim or if it really returns it, I do not know how to get it – efr Apr 27 '17 at 15:18
0

I have found a posible solution. I have used the android reflection to call TelephonyManager methods for example if i want the data Network I can use getDataNetworkType as follows:

getNetworkTypeReflection(telephonyManager, "getDataNetworkType", slot, false);

private static String getNetworkTypeReflection(final TelephonyManager telephony, final String predictedMethodName, final int slotID, final boolean isPrivate) {

        String result = null;

        try {

            final Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

            final Class<?>[] parameter = new Class[1];
            parameter[0] = int.class;
            final Method getSubtecnology;
            if (slotID != -1) {
                if (isPrivate) {
                    getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName, parameter);
                } else {
                    getSubtecnology = telephonyClass.getMethod(predictedMethodName, parameter);
                }
            } else {
                if (isPrivate) {
                    getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName);
                } else {
                    getSubtecnology = telephonyClass.getMethod(predictedMethodName);
                }
            }

            final Object obPhone;
            final Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            if (getSubtecnology != null) {
                if (slotID != -1) {
                    obPhone = getSubtecnology.invoke(telephony, obParameter);
                } else {
                    obPhone = getSubtecnology.invoke(telephony);
                }

                if (obPhone != null) {
                    result = obPhone.toString();

                }
            }
        } catch (Exception e) {
            //e.printStackTrace();
            return null;
        }
        return result;
    }

The problem is that this option only works on Android 5.1 (API22) but only in some device in others you need Android 7.0 (API24). If anyone has other options are welcome.

efr
  • 301
  • 3
  • 10