如何修复双卡手机中的Android通话问题?

huangapple go评论195阅读模式
英文:

How to fix Android calling problem in dual sim mobiles?

问题

无法在我的Android应用程序中从对话框中选择SIM卡。请检查附加的图像。
这是我的代码;

Intent callintent = new Intent(Intent.ACTION_CALL);
String strMobNo = callDialogNumber.getText().toString().trim();
callintent.setData(Uri.parse("tel:" + strMobNo));
startActivity(callintent);

错误主要发生在Android版本12上。

英文:

Can't select sim while calling from my android app.enter image description here
The sim 1 and sim 2 are disabled, can't select from dialog box. Please check the image attached.
Here is my code;

                Intent callintent = new Intent(Intent.ACTION_CALL);
                String strMobNo = callDialogNumber.getText().toString().trim();
                callintent.setData(Uri.parse("tel:" + strMobNo));
                startActivity(callintent);

the error mainly occurring on android version 12.

答案1

得分: 1

你提供的代码将无法让你在从你的Android应用程序拨打电话时选择SIM卡。这是因为Intent.ACTION_CALL意图不允许你指定要使用哪个SIM卡。

要在拨打电话时选择SIM卡,你需要使用Intent.ACTION_DIAL意图。这个意图允许你指定要拨打的电话号码,以及要使用的SIM卡。

以下是如何使用Intent.ACTION_DIAL意图来选择拨打电话时的SIM卡的代码示例:

Intent callIntent = new Intent(Intent.ACTION_DIAL);
String strMobNo = callDialogNumber.getText().toString().trim();
callIntent.setData(Uri.parse("tel:" + strMobNo));
callIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, strMobNo);
callIntent.putExtra(Intent.EXTRA_SIM_SLOT_INDEX, 1); // 1是要使用的SIM卡的索引
startActivity(callIntent);

在这段代码中,我将EXTRA_PHONE_NUMBER额外设置为我想要拨打的电话号码。我还将EXTRA_SIM_SLOT_INDEX额外设置为我想要使用的SIM卡的索引。SIM卡的索引从0开始,所以如果我想要使用第二个SIM卡,我应该将EXTRA_SIM_SLOT_INDEX额外设置为1。

一旦你进行了这些更改,你就应该能够从你的Android应用程序中在拨打电话时选择SIM卡。

英文:

The code you have provided will not allow you to select the SIM while calling from your Android app. This is because the Intent.ACTION_CALL intent does not allow you to specify which SIM to use.

To select the SIM while calling, you need to use the Intent.ACTION_DIAL intent. This intent allows you to specify the phone number to dial, as well as the SIM to use.

The following code shows how to use the Intent.ACTION_DIAL intent to select the SIM while calling:

Intent callIntent = new Intent(Intent.ACTION_DIAL);
String strMobNo = callDialogNumber.getText().toString().trim();
callIntent.setData(Uri.parse("tel:" + strMobNo));
callIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, strMobNo);
callIntent.putExtra(Intent.EXTRA_SIM_SLOT_INDEX, 1); // 1 is the index of the SIM to use
startActivity(callIntent);

In this code, I am setting the EXTRA_PHONE_NUMBER extra to the phone number I want to dial. I am also setting the EXTRA_SIM_SLOT_INDEX extra to the index of the SIM I want to use. The index of the SIM starts from 0, so if I want to use the second SIM, I should set the EXTRA_SIM_SLOT_INDEX extra to 1.

Once you have made these changes, you should be able to select the SIM while calling from your Android app.

huangapple
  • 本文由 发表于 2023年7月18日 14:15:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定