4

I used 'Subscription Manager' and 'Telephony Manager', but they don't do what I need. https://developer.android.com/reference/android/telephony/SubscriptionManager.html https://developer.android.com/reference/android/telephony/TelephonyManager.html

I found and check 2 of 3 parts of my question. This is a working code to send SMS and make call in dual sim phone:

// get info about sim slots
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append("\r\nSlots ")
                    .append("   TelephonyManager getPhoneCount: "+tm.getPhoneCount());

    sb.append("\r\nSlots ")
                    .append("   SubscriptionManager getActiveSubscriptionInfoCount: "+sm.getActiveSubscriptionInfoCount())
                    .append("   max: "+sm.getActiveSubscriptionInfoCountMax())
                    .append("\r\n");

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null) {
        for (SubscriptionInfo si : subscriptions) {
            sb.append("SIM ")
                    .append("   slot: " + si.getSimSlotIndex())
                    .append("   id: " + si.getSubscriptionId())
                    .append("   iso: " + si.getCountryIso())
                    .append("   Mcc: " + si.getMcc())
                    .append("   Mnc: " + si.getMnc())
                    .append("   CarrierName: " + si.getCarrierName()).append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append("\r\n");
        }
    }
    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

// outputs
    // Slots    TelephonyManager getPhoneCount: 2
    // Slots    SubscriptionManager getActiveSubscriptionInfoCount: 2   max: 2
    // SIM    slot: 0   id: 6   iso: ua   Mcc: 255   Mnc: 1   CarrierName: Vodafone UA | MTS UKR
    // SIM    slot: 1   id: 1   iso: ua   Mcc: 255   Mnc: 6   CarrierName: life:)

// send sms in dual sim mode
    String phoneNumber = "+38063......"
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {

        if (checkSelfPermission(Manifest.permission.SEND_SMS)
                == PackageManager.PERMISSION_DENIED) {

            Log.d("permission", "permission denied to SEND_SMS - requesting it");
            String[] permissions = {Manifest.permission.SEND_SMS};

            requestPermissions(permissions, 1);
        }
    }
    // send sms
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.getSmsManagerForSubscriptionId(6).sendTextMessage(phoneNumber, null, "Message2", null, null);
        Toast.makeText(getApplicationContext(),
                "Your sms has successfully sent!",
                Toast.LENGTH_LONG).show();
        Log.i("Dual_sim_app", "Your sms has successfully sent!");
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
                "SMS faild, please try again later!",
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
        Log.i("Dual_sim_app", "SMS faild, please try again later!");
    }
// call in dual sim mode
    String phoneNumber = "+38063......"
    Context context = this.getApplicationContext();
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, 1);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        Log.i("Dual_sim_app", "CALL_PHONE permission fail");
        return;
    }
    Intent intentt = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    intentt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intentt.putExtra("com.android.phone.force.slot", true);
    intentt.putExtra("Cdma_Supp", true);
    intentt.putExtra("simSlot", 0); //0 or 1 according to sim
    context.startActivity(intentt);

Now I need to use mobile data from each sim. How?

Joubert Vasconcelos
  • 550
  • 1
  • 7
  • 22
Enjo
  • 41
  • 1
  • 4
  • 1
    Please describe your problem more precise and show us what you have done so far. – Chris311 Jun 26 '17 at 08:59
  • I want to set second sim (for example) like sim by default sending sms ( same with call and mobile data) – Enjo Jun 26 '17 at 12:22
  • Please refer to [this](https://stackoverflow.com/help/mcve) page, in order to write an answereable question. – Chris311 Jun 27 '17 at 07:13

0 Answers0