Question Detail

How to send SMS through android program?

5 years ago Views 1423 Visit Post Reply

How can we send Send Text Message ( SMS ) to my doctor on one click In Android app programmatically


Thread Reply

alex levine

- 5 years ago

You have to add uses Permission in Manfest file to give permission app to send Sms from Android App

<uses-permission android:name="android.permission.SEND_SMS" />

I have create below function to send SMS service without open Message App in Mobile Just hit this function with where you want to send Message Mobile number it will direct send Sms.

void sendSMS(String mobileNumber) {
    // Send the rejected message ton app
    String messege = textmsgs;
    SmsManager sms = SmsManager.getDefault();
    List<String> messages = sms.divideMessage(messege);

    for (String msg : messages) {
        PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
        PendingIntent deliveredIntent = PendingIntent.getBroadcast(context, 1, new Intent("SMS_DELIVERED"), 0); // if you want to show delivery report you can use this object at last null value
        sms.sendTextMessage(mobileNumber, null, msg, sentIntent, null);
    }
}