0

当我点击电话按钮时,如何选择 skype、viber、sim1 或 sim2 等。现在,它由 sim2 调用。我想选择。我在谷歌上搜索,没有发现我的问题。

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
    startActivity(intent);
} catch (Exception e) {
    e.printStackTrace();
}

清单中的权限

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
4

3 回答 3

1

在开始意图之前重置应用首选项

Settings->Apps/Application Manager -> Default/Downloaded Apps -> Click on overflow icon (i.e. three dots icon on top right of the screen) -> Reset App Preferences.

你的代码看起来不错。

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
    startActivity(intent);
} catch (Exception e) {
    e.printStackTrace();
}
于 2017-04-28T07:54:19.263 回答
1

您需要创建一个 sim 选择器对话框并设置 sim 1 和 sim 2 选项,并根据选择的 sim 编号设置 simNumber 变量(sim1 为 0,sim2 为 1)

这是我为从特定 sim 即 SIM 1 或 SIM 2 调用而实现的代码。

代码:

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"
};

int simNumber = 0 or 1; //0 for sim1 and 1 for sim2
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
                        + phoneNumber));
                callIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

//Add slots here since different device needs different key so put all together
for (String s : simSlotName)
    intent.putExtra(s, simNumber);

//This will only work on API 22 or up
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) SimSlotHelper.getAccountHandles(context).get(simNumber))

context.startActivity(intent);

这是一个用于 sim slot helper 的类,它将通过使用两个 sim 的电信管理器来获取电话帐户句柄列表

代码:

public class SimSlotHelper {
public static List getAccountHandles(Context context) {
    Class c;
    Method m;
    TelecomManager telecomManager;
    List<PhoneAccountHandle> accountHandles;
    TelephonyManager telephony;
    telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    try {

        c = Class.forName("android.telecom.TelecomManager");
        Method m1 = c.getMethod("from", Context.class);
        telecomManager = (TelecomManager) m1.invoke(null, context);
        m = c.getMethod("getCallCapablePhoneAccounts");
        accountHandles = (List<PhoneAccountHandle>) m.invoke(telecomManager);
        return accountHandles;

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
 }
}
于 2017-04-28T08:28:59.320 回答
0

尝试使用 .ACTION_DIAL 而不是 .ACTION_CALL 。这将打开一个对话框选择器,其中安装了具有调用功能的设备中的应用程序。

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + "123456789"));
try {
    startActivity(intent);
} catch (Exception e) {
    e.printStackTrace();
}
于 2017-04-28T07:48:36.453 回答