从第二个sim打电话

Ses*_*nay 19 android phone-call dual-sim

我有一个双卡通Android手机.我正在使用此代码拨打电话:

private void callBack(String phone, Context context) {
        Intent callIntent = new Intent(Intent.ACTION_CALL)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        callIntent.setData(Uri.parse("tel:" + phone));
        context.startActivity(callIntent);

    }
Run Code Online (Sandbox Code Playgroud)

它工作正常.但它总是从sim1调用(最好是sim).如何从Sim2拨打电话?有没有办法处理双卡手机?

小智 30

这似乎适用于摩托罗拉,Micromax,HTC,三星等各种双卡设备

intent.putExtra("com.android.phone.extra.slot", 0); //For sim 1
Run Code Online (Sandbox Code Playgroud)

要么

intent.putExtra("com.android.phone.extra.slot", 1); //For sim 2
Run Code Online (Sandbox Code Playgroud)

如果不起作用试试这个,在三星S二重奏这个工作正常.

intent.putExtra("simSlot", 0); //For sim 1
Run Code Online (Sandbox Code Playgroud)

要么

intent.putExtra("simSlot", 1); //For sim 2
Run Code Online (Sandbox Code Playgroud)

不幸的是,对于这些东西,我们必须进入命中/试用模式,因为没有官方文档可用于双SIM卡支持.

  • 我的几次随机尝试之一 (2认同)

小智 5

    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);
Run Code Online (Sandbox Code Playgroud)

适用于双卡 Asus Fonepad 7 Android 5.0