Android 使用双卡设备中的指定 SIM 卡拨打电话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25524476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:31:33  来源:igfitidea点击:

Make call using a specified SIM in a Dual SIM Device

androidandroid-intenttelephonymanager

提问by class Android

I have been searching for this from past few days and I came to know that:

过去几天我一直在寻找这个,我开始知道:

"Dual SIM is not supported in Android out of the box. It is a custom modification by manufacturers, and there is no public API to control it."

“开箱即用的Android不支持双卡。这是制造商的自定义修改,没有公共API来控制它。”

There is a solution provided in the below link but its not working on my phone Samsung Galaxy S4 Mini.

下面的链接中提供了一个解决方案,但它不适用于我的手机 Samsung Galaxy S4 Mini。

Call from second sim

来自第二个 SIM 卡的呼叫

I also found this link, which I found very informative.

我还找到了这个链接,我发现它非常有用。

http://www.devlper.com/2010/06/using-android-telephonymanager/

http://www.devlper.com/2010/06/using-android-telephonymanager/

Now I know that using the following code, I might have a chance to get lucky to make it working:

现在我知道使用以下代码,我可能有机会幸运地使它工作:

Intent callIntent = new Intent(Intent.ACTION_CALL)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        callIntent.setData(Uri.parse("tel:" + phone));
        context.startActivity(callIntent);
callIntent.putExtra("com.android.phone.extra.slot", 0); //For sim 1
and
callIntent.putExtra("com.android.phone.extra.slot", 1); //For sim 2

I am not sure about this, but I have a question.

我不确定这一点,但我有一个问题。

In Settings under the SIM Card Manager section, when I have to choose a preferred SIM card for Voice Call, I get four options:

在 SIM 卡管理器部分下的设置中,当我必须为语音通话选择首选 SIM 卡时,我有四个选项:

  1. Current Network
  2. Ask Always
  3. SIM 1
  4. SIM 2
  1. 当前网络
  2. 总是问
  3. 卡 1
  4. 卡 2

When I choose Ask Always option then before making a call I am always asked for choosing a SIM Card, displayed in a Dialog Box, to make the call. My question is can I exploit this thing in my App where I press a button to make a call but it always asks me the same way it does when I chose Ask Always option.

当我选择始终询问选项时,在拨打电话之前,总是要求我选择显示在对话框中的 SIM 卡来拨打电话。我的问题是我可以在我的应用程序中利用这个东西,我按下一个按钮来拨打电话,但它总是像我选择“始终询问”选项时一样询问我。

I am sorry, I made this question lengthy, but I think it required it. Please help and big thanks in advance.

对不起,我把这个问题弄得很长,但我认为它需要它。请提前提供帮助和非常感谢。

EDIT:

编辑:

How can I achieve this, everytime I press any button (Kind of similar to Ask Always option in Settings) : Select SIM Dialog Box

我怎样才能做到这一点,每次我按下任何按钮(类似于“设置”中的“始终询问”选项): 选择 SIM 卡对话框

回答by Ajay Rawat

Code:

代码:

private final static String simSlotName[] = {
        "extra_asus_dial_use_dualsim",
        "com.android.phone.extra.slot",
        "slot",
        "simslot",
        "sim_slot",
        "subscription",
        "Subscription",
        "phone",
        "com.android.phone.DialingMode",
        "simSlot",
        "slot_id",
        "simId",
        "simnum",
        "phone_type",
        "slotId",
        "slotIdx"
};


Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "any number"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("com.android.phone.force.slot", true);
    intent.putExtra("Cdma_Supp", true);
    //Add all slots here, according to device.. (different device require different key so put all together)
    for (String s : simSlotName)
        intent.putExtra(s, 0); //0 or 1 according to sim.......

    //works only for API >= 21
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) " here You have to get phone account handle list by using telecom manger for both sims:- using this method getCallCapablePhoneAccounts()");

    context.startActivity(intent);

回答by dipanshu jindal

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:" + number));
        intent.putExtra("com.android.phone.force.slot", true);
        intent.putExtra("Cdma_Supp", true);
        if (simselected== 0) {   //0 for sim1
            for (String s : simSlotName)
                intent.putExtra(s, 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 {      1 for sim2
            for (String s : simSlotName)
                intent.putExtra(s, 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);

回答by Raj Singhania

I have an answer for this problem as I was looking for this option. Here are the steps:

当我在寻找这个选项时,我有这个问题的答案。以下是步骤:

  • first you need xposed framework and;
  • install miui application and;
  • add preferred sim option in contact
  • 首先,你需要xposed框架和;
  • 安装 miui 应用程序和;
  • 加在接触优选SIM选项