使用任何Sim卡拨打电话

时间:2018-07-30 10:16:10

标签: android

我正在开发一个Android应用程序,该应用程序根据if条件从SIM卡中拨打电话。如果满足一个条件,则该应用必须从Sim 1拨打电话,对于所有其他条件,无论默认SIM卡是什么,该应用都必须从Sim 2拨打电话。我浏览了该论坛的许多帖子,但找不到任何有用的信息。

我当前正在使用以下代码运行我的应用

// (0 for first sim and 1 for 2nd sim)
callIntent.putExtra("com.android.phone.extra.slot", 1); 

我还尝试了另一种方法

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

callIntent.putExtra("simSlotName", 1);

这两种方法均无效。帮帮我

1 个答案:

答案 0 :(得分:0)

完整代码在这里

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

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "any number"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("com.android.phone.force.slot", true);
intent.putExtra("Cdma_Supp", true);
//Add all slots here, according to device.. (different device require different key so put all together)
for (String s : simSlotName)
    intent.putExtra(s, 0); //0 or 1 according to sim.......

//works only for API >= 21
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) " here You have to get phone account handle list by using telecom manger for both sims:- using this method getCallCapablePhoneAccounts()");

context.startActivity(intent);