title: Sending SMS programmatically to multiple people getting Generic Error
body: <p>I am currently trying to develop an SMS application and allow a user to send SMS to multiple people.</p>
  
  <p>As the SMS is long i have to use the sendMultipartTextMessage which is below</p>
  
  <pre><code>private void sendSMS(final String phoneNumber, String message) {
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";
  
      SmsManager sms = SmsManager.getDefault();
      ArrayList&lt;String&gt; parts = sms.divideMessage(message);
      int messageCount = parts.size();
  
      Log.i("Message Count", "Message Count: " + messageCount);
  
      ArrayList&lt;PendingIntent&gt; deliveryIntents = new ArrayList&lt;PendingIntent&gt;();
      ArrayList&lt;PendingIntent&gt; sentIntents = new ArrayList&lt;PendingIntent&gt;();
  
      PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
      PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
  
      for (int j = 0; j &lt; messageCount; j++) {
          sentIntents.add(sentPI);
          deliveryIntents.add(deliveredPI);
      }
  
      // ---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));
  
      // ---when the SMS has been delivered---
      registerReceiver(new BroadcastReceiver() {
          @Override
          public void onReceive(Context arg0, Intent arg1) {
              switch (getResultCode()) {
  
              case Activity.RESULT_OK:
                  Toast.makeText(getBaseContext(), "SMS delivered",
                          Toast.LENGTH_SHORT).show();
                  break;
              case Activity.RESULT_CANCELED:
                  Toast.makeText(getBaseContext(), "SMS not delivered",
                          Toast.LENGTH_SHORT).show();
                  break;
              }
          }
      }, new IntentFilter(DELIVERED));
  
      sms.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents, deliveryIntents);
  }
  </code></pre>
  
  <p>I will encounter a generic error when i attempt to send it to multiple people in a loop like this and the message won't be sent. I'm suspecting it is because the message is probably 3-4 parts and the android system cannot send the message in time even with the 3000 milliseconds delay.</p>
  
  <pre><code>    for (int t = 0; t &lt; array.length; t++) {
          System.out.println("temp: " + array[t].toString());
          try {
              sendSMS(array[t].toString(), message);
              Thread.sleep(3000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>EDIT: The above code are in a AsyncTask which is executed inside a Service.</p>