23

I have a dual sim android phone. I am using this code to make a call:

private void callBack(String phone, Context context) {
        Intent callIntent = new Intent(Intent.ACTION_CALL)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        callIntent.setData(Uri.parse("tel:" + phone));
        context.startActivity(callIntent);

    }

It's working fine. But it always makes call from sim1(preferable sim). How do I make calls from Sim2? Is there a way to handle dual sim phones?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109

3 Answers3

34

This seems to work on a large range of dual sim devices as Motorola, Micromax, HTC, Samsung

intent.putExtra("com.android.phone.extra.slot", 0); //For sim 1

OR

intent.putExtra("com.android.phone.extra.slot", 1); //For sim 2

and if doesn't work try this, In Samsung S duos this works just fine.

intent.putExtra("simSlot", 0); //For sim 1

OR

intent.putExtra("simSlot", 1); //For sim 2

unfortunately for these things we have to get into hit/trial mode as no official documentation is there for dual-sim support.

dirtydexter
  • 1,063
  • 1
  • 10
  • 17
  • 1
    Thanks. Let me check it on other phones. BTW, how did you come to know about this? No where it's documented? – Seshu Vinay Oct 21 '13 at 04:50
  • 2
    One of my several random attempts –  Oct 21 '13 at 07:04
  • 1
    Is this method works on all android phones? (I tried it but it did not work on my phone) And if there any way to send sms from second sim. – user934820 Dec 07 '13 at 13:35
  • @SeshuVinay I have tried it on a micromax device but its not working. Unfortunately I don have a Samsung dualsim to test, do you know how it could be made to work on all phones. – dirtydexter Jun 24 '14 at 06:07
  • @dirtydexter No! Unfortunately, there is no official documentation for this – Seshu Vinay Jun 24 '14 at 07:15
  • @SeshuVinay I am aware about the official documentation being missing for complete dual sim support, but I am looking for some kind of hack that could help me do this. – dirtydexter Jun 24 '14 at 08:02
5
    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);

Work on dual-sim Asus Fonepad 7 Android 5.0

3

Android does not provide APIs to support dual SIM devices. SIM Card related APIs of Android only support default SIM Card(usually SIM #1). It is hardware implementation to support dual SIM on Android, therefore device manufacturer have to implement their own APIs or customize the source code to support their hardware component. You can contact to device manufacturer for dual SIM supporting SDK.

Kishore
  • 952
  • 2
  • 11
  • 31