【问题标题】:Calling intent in android with two sim cards使用两张 sim 卡在 android 中调用意图
【发布时间】:2016-09-02 13:33:22
【问题描述】:

如何通过设备中的第二张 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】:

    检查此代码:

    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

    【讨论】:

    • 不幸的是,它仅在 api>23 时有效。我如何在操作系统版本 4.1 或 4.3 中做到这一点?
    猜你喜欢
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多