Send SMS using Android code


January 23, 2013AndroidNo comments

In this tutorial we will learn how to send sms using android code.Android’s basic feature SMS is controlled by SMSManager of Telephony class.Using this we can send,receive short messages in the PDU formats.We have already seen the tutorial to send sms using way2sms and java.

Task: Creating a textarea that allows user to type messages and send to a number.

Create a new android project called SendSMS or any of your choice.Select the target version which is the min API level that application should compatible to.I chose android 4.0 Ice cream sandwich.


create a new screen layout file for the messaging interface.










In this class file we will assign variables for the message and phone number textboxes and bind a onclicklistener for the send button.

package com.example.sendsms;

import android.os.Bundle;
import android.content.DialogInterface;
import android.telephony.SmsManager;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SendSms extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
final EditText message = (EditText) findViewById(;
final EditText sendto = (EditText) findViewById(;
Button btnsend = (Button) findViewById(;
Button btnclear = (Button) findViewById(;
btnsend.setOnClickListener(new View.OnClickListener() {

	public void onClick(View v) {
	// TODO Auto-generated method stub

       SmsManager sms = SmsManager.getDefault();
	sms.sendTextMessage(sendto.toString(), null, message.getText().toString(), null, null);
       //show toast message after sending
	Toast strmsg = Toast.makeText(SendSms.this,"Sending", Toast.LENGTH_SHORT);;



btnclear.setOnClickListener(new View.OnClickListener() {

	public void onClick(View v) {
		// TODO Auto-generated method stub

	Toast strmsg = Toast.makeText(SendSms.this,"Cleared", Toast.LENGTH_SHORT);;



	public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;



You need to get declare android.permission.SEND_SMS in the manifest file.

<uses-permission android:name=”android.permission.SEND_SMS”></uses-permission>


send message using code


Related posts:

Leave a Reply