title: Sending sms in android through default sender
body: <p>I have created a simple sms app in which a particular message like 'welcome to our app' will be sent. I want sms to be sent from my no. So I set sender no as my no but it shows generic failure in toast. Can someone suggest how to set a defaultsender number in sendtextmessage() function in android.
  my code</p>
  
  <pre><code> package com.example.futuro.sms;
  
  
       public class MainActivity extends AppCompatActivity {
           private static final int MY_PERMISSIONS_REQUEST_SEND_SMS = 0;
             String phn, msg,sphn;
  
                @Override
            public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      TextView t1 = (TextView) findViewById(R.id.f);
      t1.setText("hi");
      sphn="8111802225";
      phn = "9633512318";
      String message = "Thanks for downloading our app we will contact you soon. This is ur reference number";
      int randomPIN = (int) (Math.random() * 9000) + 1000;
      String pin = String.valueOf(randomPIN);
      msg = message + "PA" + pin;
      String ms="hi";
      sendSMS(phn,sphn, ms);
  }
  
  private void sendSMS(String phoneNumber, String sender,String message) {
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";TextView t=(TextView)findViewById(R.id.f);
      t.setText(sender);
      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:
                      ContentValues values = new ContentValues();
  
                          values.put("address",phn);// txtPhoneNo.getText().toString());
                          values.put("body", msg);
  
                      getContentResolver().insert(
                              Uri.parse("content://sms/sent"), values);
                      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));
  
      SmsManager sms = SmsManager.getDefault();
      sms.sendTextMessage(phoneNumber, sender, message, sentPI, deliveredPI);
  }
      }
  </code></pre>