1

I neeed to detect target sim card of incoming call on multiple sim devices. I have tired a lot of posts and tried many solutions, but all the solutions are outdated. Not working on newer version of Android.

I tried the below solutions, nothing helps

    int simSlot = intent.getIntExtra("simSlot", -1);
    int simId = intent.getIntExtra("simId", -1);
    int slot = intent.getIntExtra("slot", -1);

These all are returns -1

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));
}

The output is always returns 0

Some articles shows it's not possible. But TrueCaller shows the target simcard for all incomming calls in all android mobiles.

I want to know solution like this

I tried so many ways nothing helps. Any help will be highly appriciated. Thanks in advance

enter image description here

Anand
  • 4,355
  • 2
  • 35
  • 45

2 Answers2

1

You can try doing this inside your BroadcastReceiver class,

    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 == "0"){
        // Incoming call from SIM1
    }
    else if(callingSIM =="1"){
        // Incoming call from SIM2
    }
    }
Maleesha97
  • 167
  • 1
  • 8
1

You can try the following solution for this using SubscriptionInfo class.

  • But this works only when the phone number is associated with the SIM card.

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
     SubscriptionManager subscriptionManager = SubscriptionManager.from(getApplicationContext());
    
     // Create a PhoneStateListener to detect incoming calls
     PhoneStateListener phoneStateListener = new PhoneStateListener() {
         @Override
         public void onCallStateChanged(int state, String phoneNumber) {
             if (state == TelephonyManager.CALL_STATE_RINGING) {
                 // Retrieve the list of active subscriptions
                 List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
                 if (subscriptionInfoList != null) {
                     // Loop through the list of active subscriptions
                     for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
                         // Retrieve the phone number of the SIM card
                         String simPhoneNumber = telephonyManager.getLine1Number(subscriptionInfo.getSubscriptionId());
                         if (simPhoneNumber != null && simPhoneNumber.equals(phoneNumber)) {
                             // The incoming call belongs to this SIM card
                             int simSlotIndex = subscriptionInfo.getSimSlotIndex();
                             Log.d(TAG, "Incoming call belongs to SIM card in slot " + simSlotIndex);
                             break;
                         }
                     }
                 }
             }
         }
     };
    

Register the PhoneStateListener,

telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Maleesha97
  • 167
  • 1
  • 8