DAY 16
ANDROID
MESSAGE SENDING
In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's. There are two ways :
1. using SmsManager to send SMS.
2. using Built in Intent to send SMS.
SmsManager API
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage("Phone No.", null, "sms Manager",null ,null);
Built-in SMS application
Intent sendintent = new Intent(Intent.ACTION_VIEW);
sendintent.put Extra("sms body","Default content");
sendintent.setType("vnd.android-dir/mms-sms");
startActivity(sendintent);
Of course, both need SEND_SMS permission
<uses-permission android: name="android.permission.SEND_SMS">
Apart from the above method, there are few other important functions available in SmsManager class. These methods are listed below −
Sr.No. | Method & Description |
---|---|
1 |
ArrayList<String> divideMessage(String text)
This method divides a message text into several fragments, none bigger than the maximum SMS message size.
|
2 |
static SmsManager getDefault()
This method is used to get the default instance of the SmsManager
|
3 |
void sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
This method is used to send a data based SMS to a specific application port.
|
4 |
void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)
Send a multi-part text based SMS.
|
5 |
void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a text based SMS.
|
You will use ACTION_VIEW action to launch an SMS client installed on your Android device. Following is simple syntax to create an intent with ACTION_VIEW action.
Intent sendintent = new Intent(Intent.ACTION_VIEW);
Intent object- Data/Type to send SMS
To send an SMS you need to specify smsto: as URI using setData() method and data type will be to vnd.android-dir/mms-sms using setType() method as follows −
smsintent.setData(Uri.parse("smsto:"));
sendintent.setType("vnd.android-dir/mms-sms");
Comments
Post a Comment