Home / Basics / Android Send SMS programmatically with delivery report – Tutorial
Android Send SMS programmatically with delivery report

Android Send SMS programmatically with delivery report – Tutorial

In this tutorial we will discuss about how to send SMS from an Android application and how to get Sent and Delivery reports for the sent SMS. Android Send SMS programmatically with delivery report is really very easy.

We will use SmsManager to send the SMS and will implement two BroadcatReceivers for sent and delivery reports.

Screenshot of the Android Send SMS programmatically with delivery report final product:

Android Send SMS programmatically with delivery report

Android Send SMS programmatically with delivery report

1. Creating Android Project, In Android Studio, create a new project by navigating to File ⇒ New Project and fill all the required details. When it prompts to select a default activity, select Blank Activity and proceed.

2. We need to add SMS user permission in your Android Manifest file, to do that open Manifest file and add the following code:

3. Let’s add some styles, Open colors.xml under res ⇒ values and add below color resources. If you don’t find colors.xml, create a new file with the name.

Also Open styles.xml under res ⇒ values and add below color resources, that will customize the app so it will look like the screenshot above.

4. Now we are need to use these files in our main activity, let’s start implementing the main layout. Open the layout file of your main activity (activity_main.xml) and modify the layout as shown below. It will has two EditText for number and message, 2 TextView for Sent and Delivery reports and a single button to send the SMS.

5. Finally open MainActivity.java and do the below changes to achieve the Android Send SMS programmatically with delivery report.

  • Instantiate your UI elements and get a reference for them, then add a ClickListener  for the send Button.
  • Create a method that takes a phoneNumber and smsMessage to send SMS and get delivery report.
  • In the method sendTextMessage, add two pending intents, one for sent report and the other for delivery report.
  • Implement your receivers in onCreate Method that would be fired and if SMS was sent or delivered and check if SMS wasn’t sent successfully.
10. Run the project and test it. You should able see the Android Send SMS programmatically with delivery report as seen in the screenshot of the final product.

Download Source Code

Summary
Article Title
Android Send SMS programmatically with delivery report
Description
Android Send SMS programmatically with delivery report, we will discuss how to send SMS from an Android application and how to get Sent and Delivery reports
Author
Organization
Android Gifts

About #AndroidGifts

#AndroidGifts

Check Also

Fresco Android Library Tutorial

Fresco Android Library Tutorial – Library #8

This is library #8 in this series 100 Library in Android , in the previous article we …

2 comments

  1. i m getting error at if phone number is empty

Leave a Reply