Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Opening SMS activity with multiple recipients specified

Tags:

android

sms

I am trying to start the phone set sms provider by starting an intent. The code I am using below is what I am using to start the intent.

    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    StringBuilder uri = new StringBuilder("sms:");
    for (int i = 0; i < contacts.size(); i++) {
        uri.append(contacts.get(i).getNumber());
        uri.append(", ");
    }
    sendIntent.putExtra("sms_body", "");
    sendIntent.setType("vnd.android-dir/mms-sms");
    sendIntent.setData(Uri.parse(uri.toString()));
    startActivity(sendIntent);

I specifically want to use this method rather than sending the message myself so the user can use their preferred sms client. I can get it going with just one number but not multiple. I can't find an example anywhere with multiple recipients. Is this possible?

Thank you in advance

like image 220
georgephillips Avatar asked Apr 22 '12 05:04

georgephillips


People also ask

What is SMS manager in Android?

android.telephony.SmsManager. Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method getDefault() . To create an instance of SmsManager associated with a specific subscription ID, call getSmsManagerForSubscriptionId(int) .

How to send SMS using Intent?

Intent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "default content"); sendIntent.

How do I open SMS app on Android?

From the Home screen, tap the Apps icon (in the QuickTap bar) > the Apps tab (if necessary) > Tools folder > Messaging .


2 Answers

Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:5551212;5551212"));
smsIntent.putExtra("sms_body", "sms message goes here");
startActivity(smsIntent);

Add a semicolon delimited list of phone numbers to "smsto:" as the URI in the Intent constructor. Also refer this LINK

like image 118
Shankar Agarwal Avatar answered Oct 22 '22 22:10

Shankar Agarwal


I tried your approach with little modification and its working properly for me.This is the modified code.

StringBuilder uri = new StringBuilder("sms:");
    for (int i = 0; i < yourarray.length; i++) {
        uri.append(yourarray[i]);
        uri.append(", ");
    }
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.setData(Uri.parse(uri.toString()));
    smsIntent.putExtra("sms_body", "Body of Message");
    startActivity(smsIntent);
like image 43
Android_dep Avatar answered Oct 22 '22 22:10

Android_dep