Звонок с указанной SIM-карты в DualSim Mobile

Я много искал это, но не получил хорошего результата.
Я пытаюсь сделать вызов из приложения, используя указанный sim
Строка x выглядит примерно так: "OK>message>*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)
..
.
ПОМОЩЬ :(


person Alaa Morad    schedule 25.03.2017    source источник


Ответы (1)


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

so :

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

И ЭТО РАБОТАЕТ СЕЙЧАС.

person Alaa Morad    schedule 24.01.2018