Vivek
Vivek

Reputation: 106

How to directly dial a number with specified sim without invoking system SIM chooser on all dual SIM android phone?

I searched and read all the questions and answers similar to this question but non is solving my problem.

I want to make an app for dialing numbers. But the problem is a system popup is asking the user to select the SIM. I want to sypply this information (the SIM through which system should make call without asking user to select the sim) to system and system makes call directly with this SIM. So I want this flow in my app:

user presses the button --> system make call through SIM 1

or

user presses the button --> system make call through SIM 2

Most of the answers on this site say that it is not possible to do such task,

but Trucaller is using this similar feature, where you press the number and it makes call directly to that number with SIM 1 or SIM 2 without system interaction.

Let me know if you require more clarification or something is missing in my question.

Upvotes: 1

Views: 1403

Answers (1)

DwlRathod
DwlRathod

Reputation: 780

Try this code:

    //0 or 1 
    int simSelected = 0;
    TelecomManager telecomManager = (TelecomManager) this.getSystemService(Context.TELECOM_SERVICE);
    List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
    Intent intent = new Intent(Intent.ACTION_CALL).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse("tel:" + "PHONE_NUMBER"));
    intent.putExtra("com.android.phone.force.slot", true);
    if (simSelected == 0) {   //0 for sim1
        intent.putExtra("com.android.phone.extra.slot", 0); //0 or 1 according to sim.......
        if (phoneAccountHandleList != null && phoneAccountHandleList.size() > 0)
            intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(0));
    } else {    //0 for sim1
        intent.putExtra("com.android.phone.extra.slot", 1); //0 or 1 according to sim.......
        if (phoneAccountHandleList != null && phoneAccountHandleList.size() > 1)
            intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(1));
    }
    startActivity(intent);

Upvotes: 2

Related Questions