title: SmsManager sendTextMessage Not Working
body: <p><strong><em>SmsManager sendTextMessage not working in some conditions.</em></strong></p>
  
  <p>I created an android application which uses SmsManager to send message and it was working fine all the time on emulator and real devices. However recently I received few complaints from my user saying that my app could not send SMS on their devices. I pretty sure all permissions are granted and no crash and error in Crashlytics report.</p>
  
  <p>I tried simulate this issue on Android Emulator and I realized that when i change cellular network type to "GSM" and change it back to "Full" several times it might cause the SmsManager sendTextMessage not working. I also added sent and delivered pending intents but none of it return error code to me. It totally no response after calling sendTextMessage method.</p>
  
  <p>Please help if you have any solution about this.</p>
  
  <p><strong>Notes:</strong></p>
  
  <ol>
  <li>Very sure all permission are granted (READ_SMS, RECEIVE_SMS, SEND_SMS, READ_PHONE_STATE...)</li>
  <li>No crash and error code from pending intent after calling sendTextMessage method.</li>
  <li>Message is less than 10 characters.</li>
  </ol>
  
  <hr>
  
  <pre><code>public void sendSMS(String phoneNumber, String message) {
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";
  
      PendingIntent sentPI = PendingIntent.getBroadcast(getContext(), 0, new Intent(
              SENT), 0);
  
      PendingIntent deliveredPI = PendingIntent.getBroadcast(getContext(), 0, new Intent(
              DELIVERED), 0);
  
      BroadcastReceiver sendSMS = new BroadcastReceiver() {
          @Override
          public void onReceive(Context arg0, Intent arg1) {
              switch (getResultCode()) {
                  case Activity.RESULT_OK:
                      Broadcast_SMSReceiver.mSMSReceiver.receivedSMS(true);
                      break;
                  case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                      Toast.makeText(getContext(), "Generic failure",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NO_SERVICE:
                      Toast.makeText(getContext(), "No service",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NULL_PDU:
                      Toast.makeText(getContext(), "Null PDU",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_RADIO_OFF:
                      Toast.makeText(getContext(), "Radio off",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_SHORT_CODE_NOT_ALLOWED:
                      Toast.makeText(getContext(), "Premium short codes denied",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_SHORT_CODE_NEVER_ALLOWED:
                      Toast.makeText(getContext(), "Premium short codes denied",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_LIMIT_EXCEEDED:
                      Toast.makeText(getContext(), "Reached the sending queue limit",
                              Toast.LENGTH_SHORT).show();
                      break;
                  default:
                      Toast.makeText(getContext(), getResultCode(),
                              Toast.LENGTH_SHORT).show();
              }
          }
      };
  
  
      BroadcastReceiver deliverSMS = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              switch (getResultCode()) {
                  case Activity.RESULT_OK:
                      Toast.makeText(getContext(), "SMS delivered",
                              Toast.LENGTH_SHORT).show();
                      break;
                  case Activity.RESULT_CANCELED:
                      Toast.makeText(getContext(), "SMS not delivered",
                              Toast.LENGTH_SHORT).show();
                      break;
              }
          }
      };
  
      getActivity().registerReceiver(sendSMS, new IntentFilter(SENT));
      getActivity().registerReceiver(deliverSMS, new IntentFilter(DELIVERED));
      try {
          SmsManager sms = SmsManager.getDefault();
          sms.sendTextMessage(phoneNumber, null, "test", sentPI, deliveredPI);
      }catch (Exception e){
          Toast.makeText(getContext(),
                  "SMS failed, please try again later ! ",
                  Toast.LENGTH_LONG).show();
          e.printStackTrace();
  
      }
  
      Broadcast_SMSReceiver.mSMSReceiver.receivedSMS(true);
  }
  </code></pre>