Detect the current/ primary SIM in Dual SIM mobile

5.4k views Asked by At

I have a dual SIM mobile on which my app displays the details of the SIM and operator. But (obviously) it detects and shows details of only SIM1 and not SIM2. Is there a way in which SIM2 details can be accessed?

I know that Android does not support dual SIM by default and that the mobile manufacturer tweaks it in such a way that Android uses the selected SIM (SIM1 or SIM2, whichever user selects) as primary (for making a call) and the other SIM is standby (kicks in when a call is received). There has to be a way to detect this primary SIM.

I am not interested in fetching both SIM details at the same time. Only require details of the SIM that has been selected by user as primary for making calls.

Any link/ working example/ suggestions, any sort of help would be highly appreciated.

Thanks

2

There are 2 answers

0
CommonsWare On

Step #1: Make a list of every Android device manufacturer that has 1+ dual-SIM devices.

Step #2: Contact those manufacturers and ask your questions of them.

As you wrote:

I know that Android does not support dual SIM by default and that the mobile manufacturer tweaks it

There is no requirement that any given device manufacturer must tweak it the same way as does any other manufacturer, and there is no requirement that any given device manufacturer must tweak it in a way that is visible to an app developer. Hence, the only way to get the information you desire, if app support is actually available, is to contact the manufacturer.

1
eGregory On

To see state of SIM1 type in console: adb shell dumpsys telephony.registry

To see state of SIM2 type in console: adb shell dumpsys telephony.registry2

mCallState changed on incoming/outgoing call. It allow to let you know which SIM card used for call

To see some additional info: adb shell getprop|grep gsm

When you invoke dumpsys from Java-application, you need android.permission.DUMP in manifest. But it not works on some new devices.

On some phones can work this code to know the default sim card:

Object tm = getSystemService(Context.TELEPHONY_SERVICE);
Method method_getDefaultSim;    
int defaultSim = -1;
try {
    method_getDefaultSim = tm.getClass().getDeclaredMethod("getDefaultSim");
    method_getDefaultSim.setAccessible(true);
    defaultSim = (Integer) method_getDefaultSim.invoke(tm);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Method method_getSmsDefaultSim;
int smsDefaultSim = -1;
try {
    method_getSmsDefaultSim = tm.getClass().getDeclaredMethod("getSmsDefaultSim");
    smsDefaultSim = (Integer) method_getSmsDefaultSim.invoke(tm);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}