title: SMS GENERIC FAILURE in Dual Sim phones Android
body: <p>I am using the SMS Manager class to send SMS through my code. The code works well in single sim phones but in some dual SIM phones, it returns me GENERIC FAILURE. I search a lot for this but found no proper solution for this. Please help me out. my code is as,</p>
  
  <pre><code>    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
              "MY_SMS_SENT"), 0);
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
              new Intent("MY_SMS_DELIVERED"), 0);
      SmsManager sms = SmsManager.getDefault();
      sms.sendTextMessage(phoneNumber, null, messageBody, sentPI, deliveredPI);
  </code></pre>
  
  <p>and my receiver is as,</p>
  
  <pre><code>    @Override
  public void onReceive(Context context, Intent intent) {
      //errorCode
      if(intent.getAction().equals("MY_SMS_SENT")) {
          switch (getResultCode()) {
          case Activity.RESULT_OK:
              Toast.makeText(context, "SMS sent",
                      Toast.LENGTH_SHORT).show();
              break;
          case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
              TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(context);
              boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
              boolean isSIM2Ready = telephonyInfo.isSIM2Ready();
              boolean isDualSIM = telephonyInfo.isDualSIM();
  
              Log.e("IS DUAL SIM", "" + isDualSIM);
              Log.e("isSIM1Ready", "" + isSIM1Ready);
              Log.e("isSIM2Ready", "" + isSIM2Ready);
  
              if(isDualSIM) {
                  if(isSIM1Ready || isSIM2Ready) {
                      Toast.makeText(context, "An Unexpected failure occured while sending SMS. Please check whether you have working SMS plan and try again later.",
                              Toast.LENGTH_LONG).show();
                  }
                  else {
                      Toast.makeText(context, "Please activate atleast one SIM for sending SMS and retry.",
                              Toast.LENGTH_LONG).show();
                  }
              }
              else {
                  if(!isSIM1Ready) {
                      Toast.makeText(context, "No SIM detected to perform this action.",
                              Toast.LENGTH_LONG).show();
                  }
                  else {
                      Toast.makeText(context, "An Unexpected failure occured while sending SMS. Please check whether you have working SMS plan and try again later.",
                              Toast.LENGTH_LONG).show();
                  }
              }
  
              break;
          case SmsManager.RESULT_ERROR_NO_SERVICE:
              Toast.makeText(context, "No service available. Please try again later.",
                      Toast.LENGTH_SHORT).show();
              break;
          case SmsManager.RESULT_ERROR_NULL_PDU:
              Toast.makeText(context, "SMS not sent. Please try again later.",
                      Toast.LENGTH_SHORT).show();
              break;
          case SmsManager.RESULT_ERROR_RADIO_OFF:
              Toast.makeText(context, "SMS Not Sent. Please try again later.",
                      Toast.LENGTH_SHORT).show();
              break;
          }
      }
      else if(intent.getAction().equals("MY_SMS_DELIVERED")) {
          switch (getResultCode()) {
          case Activity.RESULT_OK:
              Log.d("SMS STATUS", "SMS delivered");
              /* Toast.makeText(getBaseContext(), "SMS delivered",
                      Toast.LENGTH_SHORT).show();*/
              break;
          case Activity.RESULT_CANCELED:
              Log.d("SMS STATUS", "SMS not delivered");
              /*Toast.makeText(getBaseContext(), "SMS not delivered",
                      Toast.LENGTH_SHORT).show();*/
              break;
          }
      }
  }
  </code></pre>