Android Messaging Example for Sending SMS Programmatically

android-logoSimple way to Send SMS (Text Messages) from an Android Application.

Here we will discuss about how to send SMS from an Android application in a very simple way. Sending SMS from an Android application programmatically is really very easy. Lets have a line by line discussion for how to send massages in Android.
Sending SMS Programmatically

1. Create an Andeoid  project named as : SendSMSExample

2. Add Package Name: com.techblogon.sendsmsexample

3. Select Target SDK version: API 17: Android 4.2 (Jelly Bean)

Note: I am using Eclipse Indigo, all the above data is for the example attached in this post. It might be different options as per your Android setup. But don’t worry it will work for all versions. For more clarity you can download the example for “Android Messaging Example for Sending SMS Programmatically” from buttom of this post.

To make this example very simple, we will take one Android Activity. Then we will take 2 EditText for getting receipent number and composing SMS. Then we will use one more control as a buttom called ‘Send’ to sending the SMS to the destination number. I think this is fair enough to learn how to send the SMS in Android.

1. Add below SMS user permission in your Android Manifest file.

Your project’s Manifest file will be looks like below.

AndroidManifest.xml

 2. Add below xml file content in your source folder for GUI part. This xml file will hold 2 EditText and One button for sending SMS. In my example the xml file name is activity_send_sms.xml.

Path: \res\layout\

File Name: activity_send_sms.xml

3. Now coming to java source code for sending SMS from our Android application.

Your project’s Activity.Java file will looks like below. In my example it looks like below code snippet. You can also get the delivery report and error code for the SMS you sent. Please refer to the below code.

Path: \src\com\techblogon\sendsmsexample\

File Name: SendSms.Java

Note: In the above code snipt, you can also get SMS devilery report and error code if the SMS sending is failed.

4. Now build and run your application on Device and Emulator and enjoy Android coding.

 

Post By SmrutiRanjan (54 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon

Connect

2 Responses to Android Messaging Example for Sending SMS Programmatically

  1. Sudhansu says:

    Hi,
    I tried your sms sending code (APP code) but its not working. It gives ‘error’ message.

    I have copied all the code as it is, only package name is different (by default package name).

    Please let me know what are the changes or addition i have to make so that it works.

    Sudhansu

    • SmrutiRanjan says:

      Hi Sudhanhu,
      I have added new code. please check again.
      Make sure to add the user permission in the andrpid manifest file?
      android:name=”com.techblogon.sendsmsexample.SendSms”

Leave a Reply

Your email address will not be published. Required fields are marked *


eight + 3 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">