使用两张SIM卡在android中调用intent

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

我如何才能从我的设备中的第二张 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卡上拨打电话呢?

android call
1个回答
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(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
    } catch (Exception e) {
        e.printStackTrace();
    }

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

来自这个链接

© www.soinside.com 2019 - 2024. All rights reserved.