简体   繁体   English

如何在不调用所有双SIM卡Android手机上的系统SIM选择器的情况下直接拨打带有指定SIM卡的号码?

[英]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. 但是问题是系统弹出窗口要求用户选择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. 我想将此信息(系统要求通过SIM卡拨打电话而不要求用户选择SIM卡)发送给系统,然后系统直接与此SIM卡进行通话。 So I want this flow in my app: 所以我想要在我的应用程序中执行以下流程:

user presses the button --> system make call through SIM 1 用户按下按钮->系统通过SIM 1拨打电话

or 要么

user presses the button --> system make call through SIM 2 用户按下按钮->系统通过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. 但是Trucaller使用的是此类似功能,您只需按该号码,即可使用SIM 1或SIM 2直接呼叫该号码,而无需系统交互。

Let me know if you require more clarification or something is missing in my question. 让我知道您是否需要更多说明,或者我的问题中有什么遗漏。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM