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

问题描述 投票:0回答:4

过去几天我一直在寻找这个,我发现:

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

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

从第二个SIM卡拨打电话

我还找到了这个链接,我发现它提供了非常丰富的信息。

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

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

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

我对此不太确定,但我有一个问题。

在“SIM 卡管理器”部分下的“设置”中,当我必须选择用于语音通话的首选 SIM 卡时,我会看到四个选项:

  1. 当前网络
  2. 始终询问
  3. SIM卡1
  4. SIM 2

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

抱歉,我问了这个问题很长,但我认为这是必要的。请提前提供帮助并非常感谢。

编辑:

每次按任意按钮时,如何实现此目的(类似于“设置”中的“始终询问”选项): Select SIM Dialog Box

android android-intent telephonymanager
4个回答
15
投票

代码:

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

13
投票
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);

0
投票
  // SIM selection buttons
        binding.sim1Button.setOnClickListener {
            Log.d("DialerBottomSheet", "SIM 1 button clicked")
            handleCallButtonClick(0)
        }
        binding.sim2Button.setOnClickListener {
            Log.d("DialerBottomSheet", "SIM 2 button clicked")
            handleCallButtonClick(1)
        }
     //Handle if the sim is not available and user initiates the call -
    private fun handleCallButtonClick(simSlot: Int) {
        val telephonyManager = requireContext().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager

        if (isSimAvailable(telephonyManager, simSlot)) {
            val number = binding.dialedNumberDisplay.text.toString() //some view where the dialed number shows 
            if (number.isNotEmpty()) {
                Log.d("DialerBottomSheet", "Initiating check for number: $number on SIM slot: $simSlot")
                checkNumberExistsAndMakeCall(number, simSlot)
            } else {
                Toast.makeText(context, "Please enter a number.", Toast.LENGTH_SHORT).show()
            }
        } else {
            // SIM is not available
            Toast.makeText(context, "Please Insert SIM in slot ${simSlot + 1}.", Toast.LENGTH_SHORT).show()
            Log.d("DialerBottomSheet", "SIM slot $simSlot is not available.")
        }
    }

    private fun isSimAvailable(telephonyManager: TelephonyManager, simSlot: Int): Boolean {
        val simState: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            telephonyManager.getSimState(simSlot)
        } else {
            if (simSlot == 0) telephonyManager.simState else TelephonyManager.SIM_STATE_UNKNOWN
        }

        return simState == TelephonyManager.SIM_STATE_READY
    }

-5
投票

我有这个问题的答案,因为我正在寻找这个选项。步骤如下:

  • 首先你需要xposed框架;
  • 安装miui应用程序;
  • 在联系人中添加首选 SIM 选项
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.