title: SMSManager returns RESULT_ERROR_GENERIC_FAILURE despite trying everything
body: <p>I am trying to create a feature in my app which can send SMS to multiple contacts in background. I am using <code>SMS Manager API</code> to do the same. However, everytime <code>RESULT_ERROR_GENERIC_FAILURE</code> returns. I read lot of similar posts on stack overflow and tried all the solutions but none of them seems to work for me. To be specific, I have tried following:</p>
  
  <ol>
  <li>Change phone number format to "+91xxxxxxxxxx", "9xxxxxxxxx", "91xxxxxxxxxx"</li>
  <li>Checked the SIM balance</li>
  <li>SMS Service centre number is also valid</li>
  <li>SMS Message is well within 160 characters</li>
  <li>Delay sending multiple SMS</li>
  </ol>
  
  <p>Here is how I am sending SMS:</p>
  
  <pre><code>for (int index = 0; index &lt; contactsList.size(); index++) {
              final String phonenumber = contactsList.get(index).getPhone().substring(1);
  
              if (index == 0) {
                  sendSMS(phonenumber.trim(), sms, contactsList);
              } else {
                  new Handler().postDelayed(new Runnable() {
                      public void run() {
  
                          sendSMS(phonenumber.trim(), sms, contactsList);
                      }
                  }, 1000 * 20);
              }
          }
  </code></pre>
  
  <p>Here is <code>sendSMS</code> method:</p>
  
  <pre><code>private void sendSMS(String phoneNumber, final String message, final List&lt;MyContactsActivity.ContactsRow&gt; list) {
          String SENT = "SMS_SENT";
          String DELIVERED = "SMS_DELIVERED";
  
          PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(
                  SENT), 0);
  
          PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,
                  new Intent(DELIVERED), 0);
  
          // ---when the SMS has been sent---
          context.registerReceiver(new BroadcastReceiver() {
              @Override
              public void onReceive(Context arg0, Intent arg1) {
                  switch (getResultCode()) {
                      case Activity.RESULT_OK:
                          ContentValues values = new ContentValues();
                          for (int i = 0; i &lt; list.size() - 1; i++) {
                              values.put("address", list.get(i).getPhone());
                              values.put("body", message);
                          }
                          context.getContentResolver().insert(
                                  Uri.parse("content://sms/sent"), values);
                          Toast.makeText(context, "SMS sent", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "1");
                          break;
                      case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                          Toast.makeText(context, "Generic failure", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "2");
                          break;
                      case SmsManager.RESULT_ERROR_NO_SERVICE:
                          Toast.makeText(context, "No service", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "3");
                          break;
                      case SmsManager.RESULT_ERROR_NULL_PDU:
                          Toast.makeText(context, "Null PDU", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "4");
                          break;
                      case SmsManager.RESULT_ERROR_RADIO_OFF:
                          Toast.makeText(context, "Radio off", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "5");
                          break;
                  }
              }
          }, new IntentFilter(SENT));
  
          // ---when the SMS has been delivered---
          context.registerReceiver(new BroadcastReceiver() {
              @Override
              public void onReceive(Context arg0, Intent arg1) {
                  switch (getResultCode()) {
                      case Activity.RESULT_OK:
                          Toast.makeText(context, "SMS delivered", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "6");
                          break;
                      case Activity.RESULT_CANCELED:
                          Toast.makeText(context, "SMS not delivered", Toast.LENGTH_SHORT).show();
                          Log.e("Panic", "7");
                          break;
                  }
              }
          }, new IntentFilter(DELIVERED));
  
          SmsManager sms = SmsManager.getDefault();
          sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
      }
  </code></pre>
  
  <p>Here are my relevant manifest permissions:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.SEND_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
  </code></pre>
  
  <p><strong>NOTE: I am testing my app on real device running Android 6. I have checked runtime permissions as well as they are enabled.</strong></p>
  
  <p>Can anyone please tell me what I am doing wrong??</p>