Sending a Text Message Over the Phone Using SmsManager in Android
This article is about sending a text SMS over the phone using the SMSManager class in an Android application. For this, a basic knowledge of the fundamentals of android app development, creating a new project, running an android app, Views, and handling of click event buttons is required.
SMSManager class manages operations like sending a text message, data message, and multimedia messages (MMS). For sending a text message method sendTextMessage() is used likewise for multimedia message sendMultimediaMessage() and for data message sendDataMessage() method is used. The details of each function are:
Function | Description |
---|---|
sendTextMessage() | sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, long messageId) |
sendDataMessage() | sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) |
sendMultimediaMessage() | sendMultimediaMessage(Context context, Uri contentUri, String locationUrl, Bundle configOverrides, PendingIntent sentIntent |
Below is an example of a basic application that sends a text message.
Approach:
Step 1: Create a new Android Application.
Step 2: Go to AndroidManifest.xml.
app->Manifest->AndroidManifest.xml
Step 3: In AndroidManifest.xml add the permission to send SMS. It will permit an android application to send SMS.
<uses-permission android:name=” android.permission.SEND_SMS ” />
Please Login to comment...