Android - Sending SMS: Two Basic Examples
Android - Sending SMS: Two Basic Examples
SmsManager API
Apart from the above method, there are few other important functions available in SmsManager
class. These methods are listed below −
This method is used to send a data based SMS to a specific application port.
void sendMultipartTextMessage(String destinationAddress, String scAddress,
ArrayList<String> parts, ArrayList<PendingIntent> sentIntents,
4 ArrayList<PendingIntent> deliveryIntents)
Example
Following example shows you in practical how to use SmsManager object to send an SMS to the
given mobile number.
To experiment with this example, you will need actual Mobile device equipped with latest Android OS,
otherwise you will have to struggle with emulator which may not work.
Step Description
You will use Android Studio IDE to create an Android application and name it as tutorialspoint
1 under a package com.example.tutorialspoint. While creating this project, make sure you Target
SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.
2 Modify src/MainActivity.java file and add required code to take care of sending email.
Modify layout XML file res/layout/activity_main.xml add any GUI component if required. I'm
3 adding a simple GUI to take mobile number and SMS text to be sent and a simple button to send
SMS.
No need to define default string constants at res/values/strings.xml. Android studio takes care of
4
default constants.
Run the application to launch Android emulator and verify the result of the changes done in the
6
application.