coder_For_Life22
coder_For_Life22

Reputation: 26971

How to send text message to more than 1 number?

I am trying to have a list of contact numbers.

I want to know is there a way to send a text message to more than 1 number iprogrammatically in Android?

If so how?

Upvotes: 6

Views: 16697

Answers (2)

Shiv Kumar
Shiv Kumar

Reputation: 675

for group sms or multiple sms use this

  Intent i = new Intent(android.content.Intent.ACTION_VIEW);
    i.putExtra("address", "987385438; 750313; 971855;84393");
    i.putExtra("sms_body", "Testing you!");
    i.setType("vnd.android-dir/mms-sms");
    startActivity(i);
//use permission: <uses-permission android:name="android.permission.SEND_SMS"/>

you can modify this "9873854; 750313; 971855; 84393" with your contact number

Upvotes: 8

Matthew Rudy
Matthew Rudy

Reputation: 16834

You can't do this via Intent, as the android SMS app doesn't allow multiple recipients.

You can try using the SmsManager class.

First of all you need to request the permission android.permission.SEND_SMS in your AndroidManifest.

Then you can do something along these lines.

// you need to import the Sms Manager
import android.telephony.SmsManager;

// fetch the Sms Manager
SmsManager sms = SmsManager.getDefault();

// the message
String message = "Hello";

// the phone numbers we want to send to
String numbers[] = {"555123456789", "555987654321"};

for(String number : numbers) {
  sms.sendTextMessage(number, null, message, null, null);
}


Update: Added how to split a comma-separated string

// string input by a user
String userInput = "122323,12344221,1323442";

// split it between any commas, stripping whitespace afterwards
String numbers[] = userInput.split(", *");

Upvotes: 10

Related Questions