用两张sim卡调用android的意图

时间:2016-09-02 13:33:22

标签: android call

我如何打算从我的设备中的第二张SIM卡拨打电话?我找到了这种方式:

    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.putExtra("simSlot", selectedSlot);
    callIntent.setData(Uri.parse("tel:" + tel));
    startActivity(callIntent);

其中selectedSlot可以是0或1(第一或第二个sim)。但它确实有效。我换了行

    callIntent.putExtra("simSlot", selectedSlot);

到行

    callIntent.putExtra("com.android.phone.extra.slot", selectedSlot);

但它也不起作用。那么,我怎样才能打算从第二张SIM卡打电话?

1 个答案:

答案 0 :(得分:0)

检查此代码:

final Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumberOrUssd));
    final int simSlotIndex = 1; //Second sim slot

    try {
        final Method getSubIdMethod = SubscriptionManager.class.getDeclaredMethod("getSubId", int.class);
        getSubIdMethod.setAccessible(true);
        final long subIdForSlot = ((long[]) getSubIdMethod.invoke(SubscriptionManager.class, simSlotIndex))[0];

        final ComponentName componentName = new ComponentName("com.android.phone", "com.android.services.telephony.TelephonyConnectionService");
        final PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, String.valueOf(subIdForSlot));
        intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandle);
    } catch (Exception e) {
        e.printStackTrace();
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

来自此link