如何以编程方式使用 SMS 管理器在双 SIM 卡手机中发送 SMS 之前提示选择 SIM 卡?

How to prompt for sim selection before sending an SMS in dual sim phones using SMS manager programmatically?

How to find SubscriptionId by prompting sim selection?

 SmsManager smsManager = null;
                   if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
                     smsManager = SmsManager.getSmsManagerForSubscriptionId();
                   }else{
                       smsManager = SmsManager.getDefault();
                   }`

里面需要订阅getSmsManagerForSubscriptionId()

您可以subscriptionManagerObj.getActiveSubscriptionInfoList()获取基于Sim Slot的subscriptionId。基于 documentation

Get the SubscriptionInfo(s) of the currently inserted SIM(s). The records will be sorted by getSimSlotIndex() then by getSubscriptionId()

 SmsManager smsManager = null;
 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {

    SubscriptionManager subscriptionManager = (SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    List<SubscriptionInfo> subscriptionInfoList=subscriptionManager.getActiveSubscriptionInfoList();
    int subId = subscriptionInfoList.get(0).getSubscriptionId();// change index to 1 if you want to get Subscrption Id for slot 1.
    smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);

 }else{
      smsManager = SmsManager.getDefault();
 }