Send sms using sim selection option

前端 未结 3 1448
栀梦
栀梦 2021-01-16 19:24

I have tried Android SDK above 5.1 OS. I want to send sms using SIM selection option. I tried this Program. It\'s taking sim1 only. It does not take second sim.

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 20:03

    Finally, I found exact Sim Selection Option for above android os version 5.1 and above.

    public void sendDualSimSMSOption(final String ToaddrmobileNo, final String message) {
    
    // detect os is below 22 or not
    if (Build.VERSION.SDK_INT >= 22) {
    
    final PendingIntent PendingIntent1 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.SENT), 0);
    final PendingIntent PendingIntent2 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.DELIVERED), 0);
    
    SubscriptionManager localSubscripManager = SubscriptionManager.from(mContext);
    
    ArrayList saveSubscripID = new ArrayList();
    ArrayList saveSimOperatorNames = new ArrayList();
    ArrayList saveSimSerialNumbers = new ArrayList();
    final int[] subscripInformationArray = new int[2];
    
    if (localSubscripManager.getActiveSubscriptionInfoCount() > 1) {
    List localList = localSubscripManager.getActivesubscripInformationList();
    final String[] arrayOfStringData = new String[localList.size()];
    int i = 0;
    Iterator localIterator = localList.iterator();
    
    while (localIterator.hasNext()) {
    SubscriptionInfo localSubscriptionInfo = (SubscriptionInfo) localIterator.next();
    localSubscriptionInfo.getSubscriptionId();
    Log.v("SIM", "22 api level..got dual sim: ");
    int j = i + 1;
    String SimCarrierName = (localSubscriptionInfo.getCarrierName().toString().trim());
    String SimDisplayName = (localSubscriptionInfo.getDisplayName().toString().trim());
    String SimSerialNo = (localSubscriptionInfo.getIccId().toString().trim());
    if( SimCarrierName != null && SimCarrierName.length() > 0)
    {
    arrayOfStringData[i] = SimCarrierName ;
    Log.v('SIM', "SIM.getCarrierName:", arrayOfStringData[i]);
    }
    else {
    arrayOfStringData[i] = SimDisplayName ;
    Log.v('SIM', "SIM.SimDisplayName:", arrayOfStringData[i]);
    }
    i = j;
    }
    
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getApplicationContext());
    List subscripInformationList = subscriptionManager.getActivesubscripInformationList();
    for (SubscriptionInfo subscriptionInfo : subscripInformationList) {
    int subscriptionId = subscriptionInfo.getSubscriptionId();
    Log.v('SIM', "SIM.subscriptionId:",""+subscriptionId);
    }
    
    for (i = 0; i < subscripInformationList.size(); i++) {
    Log.v("SIM", "DUal SIm:subscripInformationList:" + subscripInformationList.get(i));
    Log.v("SIM", "DUal SIm:getSubscriptionId:" + subscripInformationList.get(i).getSubscriptionId());
    subscripInformationArray[i] = subscripInformationList.get(i).getSubscriptionId();
    saveSubscripID.add(subscripInformationList.get(i).getSubscriptionId());
    saveSimSerialNumbers.add(subscripInformationList.get(i).getIccId());
    }
    
    for (i = 0; i < arrayOfStringData.length; i++) {
    Log.v("SIM", "DUal SIm:arrayOfStringData:" + arrayOfStringData[i]);
    Log.v("SIM", "DUal SIm:subscripInformationArray:"+ subscripInformationArray[i]);
    if( arrayOfStringData[i] != null && arrayOfStringData[i].length() > 0)
    {
    saveSimOperatorNames.add(arrayOfStringData[i]); 
    }
    else{
    saveSimOperatorNames.add("Sim "+(i+1));
    }
    }
    // this is the method to show sim selection dialog with above sim serials info.
    SimSelection_ShowDialogBox(context, ToAddrMobNo, message,saveSubscripId, saveSimOperaNames,saveSimSerialNumbers);
    }
    }
    else{
    // else part. default sim taking to send sms
    }
    

    }

提交回复
热议问题