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?

0

3 Answers 3

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.

6
  • 1
    Thanks. Let me check it on other phones. BTW, how did you come to know about this? No where it's documented? Oct 21, 2013 at 4:50
  • 2
    One of my several random attempts
    – user1411614
    Oct 21, 2013 at 7: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 7, 2013 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. Jun 24, 2014 at 6:07
  • @dirtydexter No! Unfortunately, there is no official documentation for this Jun 24, 2014 at 7:15
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.

1
  • Very unfortunate Aug 18, 2023 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.