13

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)?

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
  • `intent.getExtras().getInt("item")` <--Shouldn't you be using `item` rather than `"item"`? – Michael Jan 14 '20 at 11:34
  • Also, have you tried printing all the extras that the Intent _does_ contain, to see if there's a difference in naming compared to what you're assuming? – Michael Jan 14 '20 at 11:38
  • it always returns 0 whether with "item" or item. – Alireza Noorali Jan 14 '20 at 11:51
  • Well, `"item"` is almost certainly incorrect in this context. Like I said, try printing what you have rather than what you're expecting. Although this whole solution looks like a bit of a hack, so any usable key that you find might still not work on some devices. – Michael Jan 14 '20 at 12:15

1 Answers1

2

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.

dgp
  • 683
  • 3
  • 13
  • 1
    Because the answer is simply an explanation, I cannot definitively approve or reject it. But as it turns out, the answer is logical. – Alireza Noorali Jan 21 '20 at 12:06