title: SMS queue Handling for failure SMS
body: <p>I am developing an app which perform an action on:</p>
  
  <ul>
  <li>Receiving SMS</li>
  <li>Sending SMS</li>
  <li>Doing some computational Task to Sender.</li>
  </ul>
  
  <p>Is it possible that SMS failed to send. Can any one tell me how to manage the queue of failed sent SMS messages and keep retrying to send them after some time.</p>
  
  <p>I have seen the code but don't know how to handle queue of SMS and resend them. </p>
  
  <p>Here is Code:</p>
  
  <pre><code>private void sendSMS(String phoneNumber, String message)
  {        
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";
  
      PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
          new Intent(SENT), 0);
  
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
          new Intent(DELIVERED), 0);
  
      //---when the SMS has been sent---
      registerReceiver(new BroadcastReceiver(){
          @Override
          public void onReceive(Context arg0, Intent arg1) {
              switch (getResultCode())
              {
                  case Activity.RESULT_OK:
                      Toast.makeText(getBaseContext(), "SMS sent", 
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                      Toast.makeText(getBaseContext(), "Generic failure", 
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NO_SERVICE:
                      Toast.makeText(getBaseContext(), "No service", 
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NULL_PDU:
                      Toast.makeText(getBaseContext(), "Null PDU", 
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_RADIO_OFF:
                      Toast.makeText(getBaseContext(), "Radio off", 
                              Toast.LENGTH_SHORT).show();
                      break;
              }
          }
      }, new IntentFilter(SENT));
      SmsManager sms = SmsManager.getDefault();
      sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);   
  }
  </code></pre>