android 使用DualSim移动的中指定的SIM卡拨打电话

prdp8dxp  于 2022-12-25  发布在  Android
关注(0)|答案(1)|浏览(225)

我一直在寻找这个,但没有得到很好的结果。
我正在尝试使用指定的SIM卡从应用程序内部拨打电话
字符串x是这样的:“确定〉消息〉*111〉1〉〉〉”

public void test_call(String x) {
    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"
    };
    String encodedHash = Uri.encode("#");
    String[] data = x.split(">");
    if (!data[4].equals("1") && !data[4].equals("0")) {
        Log.d("data :", "E:" + data[4]);
        G.is_busy = 0;
        return;
    }
    String ussd = data[3] + encodedHash;
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd));
    Log.d("Sim",data[4]);
    intent.putExtra("com.android.phone.force.slot", true);
    for (String s : simSlotName) {
        Log.d("S","s :"+s+"="+data[4]);
        intent.putExtra(s, data[4]); // 0 for sim1 , 1 for sim2
    }

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this,
                "Call failed, please try again later.",
                Toast.LENGTH_SHORT).show();
        return;
    }
    //this.startActivityForResult(intent,1);
    startActivity(intent);
    G.needscall = "";
}

这是工作正常,除了它总是使用sim 0,即使默认的SIM卡在移动的是SIM 1!(Android 5. 1. 1)
这只是使用早期版本中的默认SIM
删除此行

intent.putExtra(s, data[4]);

使应用程序使用默认sim卡拨号(5.1.1)
..

帮助:(

wgx48brx

wgx48brx1#

public void call(String simtoiuse, String code) {
        
        String encodedHash = Uri.encode("#");
        String ussd = code + encodedHash; // assuming the USSD code to dail is always sent without the # at the end 

        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd));
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
return; // can put an error message or any thing you want to handle the missing permission 
        String[] strArr = new String[]{
                "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.putExtra("com.android.phone.force.slot", true); 
        intent.putExtra("Cdma_Supp", true); // this was missing
        for (String putExtra : strArr) intent.putExtra(putExtra, sim);
        if (Build.VERSION.SDK_INT >= 23) {
// also this must be added for api 23
              Object obj;
              List callCapablePhoneAccounts = ((TelecomManager) this.getSystemService(TELECOM_SERVICE)).getCallCapablePhoneAccounts();
              String str3 = "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
              if (callCapablePhoneAccounts != null && callCapablePhoneAccounts.size() > 0) {
                  try {
                      obj = callCapablePhoneAccounts.get(sim);
                      intent.putExtra(str3, (Parcelable) obj);
                  } catch (Exception e){} // if the device is 1 sim only this may generate an exception
              }
        }
        startActivity(intent);
// these next lines were missing in my code too.
        intent.replaceExtras(new Bundle()); 
        intent.setAction(null);
        intent.setData(null);
        intent.setFlags(0);
    }

因此:

call("0","*100"); // will use the first sim to dial *100#
call("1","*100") ; // will use the second sim to dial *100#

现在起作用了。

相关问题