Android send SMS automatically on button click
the easy way is to use SmsManager.Telephony.
You can use the build in Intent also:
buttonSendSms_intent.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String smsNumber = edittextSmsNumber.getText().toString();
String smsText = edittextSmsText.getText().toString();
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
}});
Try this
private static final String SMS_SENT_INTENT_FILTER = "com.yourapp.sms_send";
private static final String SMS_DELIVERED_INTENT_FILTER = "com.yourapp.sms_delivered";
String message = "hey, this is my message";
String phnNo = " " //preferable use complete international number
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
SMS_SENT_INTENT_FILTER), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(
SMS_DELIVERED_INTENT_FILTER), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phnNo, null, message, sentPI, deliveredPI);
Try this code:
String messageToSend = "this is a message";
String number = "2121234567";
SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
With regards to the number, you need to enter the number as if you were calling it from the phone or sending an sms message in the normal manner.