Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 761
Alireza Noorali Avatar asked Nov 16 '19 09:11

Alireza Noorali


Video Answer


2 Answers

If you have done like this it should work. make sure your testing device runs on Android 5.1 or above. dual sim support is added in v 5.1 (Check here)

public class IncomingCallInterceptor extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    String callingSIM = "";
    Bundle bundle = intent.getExtras();
    callingSIM = String.valueOf(bundle.getInt("simId", -1));

    if(callingSIM.equals("0")){
           // Incoming call from SIM1
        } else if(callingSIM.equals("1")){
           // Incoming call from SIM2
        }
    }
}

Make sure you added the below permission in manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

NOTE :

These values need not to come all the time. network provider support is required .Please read the documentation here

Carrier id of the current subscription. Return UNKNOWN_CARRIER_ID if the subscription is unavailable or the carrier cannot be identified.

like image 140
droidev Avatar answered Oct 13 '22 01:10

droidev


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.

like image 23
dgp Avatar answered Oct 13 '22 01:10

dgp