javaandroidbroadcastreceiverdual-simincoming-call

Detecting target SimCard of incoming call in Multi-Sim devices


I've read a lot of posts and tried many solutions, but the common point of all posts was that they were all outdated and at least I couldn't find a solution that would work on newer versions of Android.

Post 1, Result: intent.getExtras().getInt("simId", -1) always returns -1

Post 2, Result: intent.getExtras().getInt("slot", -1) always returns -1

Post 3, Result:

String[] array = new String[]{
        "extra_asus_dial_use_dualsim",
        "com.android.phone.extra.slot",
        "slot",
        "simslot",
        "sim_slot",
        "subscription",
        "Subscription",
        "phone",
        "com.android.phone.DialingMode",
        "simSlot",
        "slot_id",
        "simId",
        "simnum",
        "phone_type",
        "slotId",
        "slotIdx"
};

for (String item :
        array) {
    Log.i(TAG, "Sim Card - " + item + " -----> " + intent.getExtras().getInt(item));
}

Logs:

PhoneCallReceiver: Sim Card - extra_asus_dial_use_dualsim -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.extra.slot -----> 0
PhoneCallReceiver: Sim Card - slot -----> 0
PhoneCallReceiver: Sim Card - simslot -----> 0
PhoneCallReceiver: Sim Card - sim_slot -----> 0
PhoneCallReceiver: Sim Card - subscription -----> 0
PhoneCallReceiver: Sim Card - Subscription -----> 0
PhoneCallReceiver: Sim Card - phone -----> 0
PhoneCallReceiver: Sim Card - com.android.phone.DialingMode -----> 0
PhoneCallReceiver: Sim Card - simSlot -----> 0
PhoneCallReceiver: Sim Card - slot_id -----> 0
PhoneCallReceiver: Sim Card - simId -----> 0
PhoneCallReceiver: Sim Card - simnum -----> 0
PhoneCallReceiver: Sim Card - phone_type -----> 0
PhoneCallReceiver: Sim Card - slotId -----> 0
PhoneCallReceiver: Sim Card - slotIdx -----> 0

it displays the same logs with the same value 0 for first SimCard and second SimCard.

I've also tried other similar posts. None worked on new versions of android!

Is there another solution that works on newer versions of Android (7.0 or higher)?


Solution

  • Officially, the only documented value provided by the intent is the phone number.

    Some constructors add other values like sim slot number in the intent, but this is not mandatory. This is why there are so many slot keys names possible, like those presented in post 3, each constructor adding his own implementation.

    It's also possible some constructor didn't add this value in some models, and that's certainly the case on your model. There is no way of finding this value if the constructor don't deliver it.