Introduction
In this article we will explore all possible ways to achieve this simple yet very useful task.
There are two possible ways to send a text message from an Android app
1. The first way is to send it programmatically from your application.
Step 1- And permission in your AndroidManifest.xml
file
<uses-permission android:name="android.permission.SEND_SMS" />
Step 2 –
Import the package –
import android.telephony.SmsManager
Step 3 – Create New function for send SMS
public void sendSMS() {
String phoneNumber = "0123456789";
String message = "Checking SMS From GP!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
The method sendTextMessage
of class SmsManager
sends a text based SMS.
Method Detail-
public void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
If you use the code above you will able to send messages with length less than or equal to 160 characters only.
public void sendLongSMS() {
String phoneNumber = "0123456789";
String message = "Hello World! Now we are going to demonstrate " +
"how to send a message with more than 160 characters from your Android application.";
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);
}
The method sendMultipartTextMessage
of class SmsManager
sends a multi-part text based SMS
2. The second way is to send it by invoking the built-in SMS application.
waiting. For tomorrow. Sorry.. .