1

How can i make intent to call from second sim card in my device? I have found this way:

    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.putExtra("simSlot", selectedSlot);
    callIntent.setData(Uri.parse("tel:" + tel));
    startActivity(callIntent);

where selectedSlot may be 0 or 1 (first or second sim). But it doest work. I replaced line

    callIntent.putExtra("simSlot", selectedSlot);

to line

    callIntent.putExtra("com.android.phone.extra.slot", selectedSlot);

but it doesnt work too. So, how can i to make intent to call from second sim card??

Alex D.
  • 1,424
  • 15
  • 40

1 Answers1

0

check with this code:

final Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumberOrUssd));
    final int simSlotIndex = 1; //Second sim slot

    try {
        final Method getSubIdMethod = SubscriptionManager.class.getDeclaredMethod("getSubId", int.class);
        getSubIdMethod.setAccessible(true);
        final long subIdForSlot = ((long[]) getSubIdMethod.invoke(SubscriptionManager.class, simSlotIndex))[0];

        final ComponentName componentName = new ComponentName("com.android.phone", "com.android.services.telephony.TelephonyConnectionService");
        final PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, String.valueOf(subIdForSlot));
        intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandle);
    } catch (Exception e) {
        e.printStackTrace();
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

it is from this link

Community
  • 1
  • 1
Haniyeh Khaksar
  • 774
  • 4
  • 20