I want to know if there is anyway that I can send sms to multiple number of people using the SmsManager. I know that I can run a loop through the contacts and send sms individually but I figured that there may be a way to do this.
The code I use is given below:
SmsManager.getDefault().sendTextMessage("PHONE_NOS", null,msg.getText().toString(), sentPI, deliveredPI);
PS: I have tried using ";" as a separator. But the only thing that happens is that it sends an sms only to the first person in the list.
For the benefit of people who are seeing this late, its not possible to send SMS to multiple people. As Bill Mote has pointed out, if there was such a thing possible, there would have been an API which would have taken a "List-of-numbers" as an argument. So the only possible solution is to have an iterator for the numbers and send them one at a time.
How to send mass text individually on Android? If you want to send mass text without group message using Android phone, there is no shortcut but to send the text to each contact one by one or use a third-party messaging app.
The net-net-net here is it cannot be done without iterating through a loop and sending 1 message to 1 addressee.
I spent 1/2 a Saturday trying to do this very thing. I could not make it work with ";", ",", " ", or "\n". I should have tried hard-coding 2 addressees separated by all the delimiters first, but I did learn a valuable lesson about the Android SDK: if they wanted you to send to more than 1 addressee at a time then they'd accept an ArrayList or an array of Strings rather than a singular String ;)
protected void sendMsg(Context context, SmsMessage smsMessage) {
SmsManager smsMgr = SmsManager.getDefault();
ArrayList<string> smsMessageText = smsMgr.divideMessage(smsMessage.getMsgBody());
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);
int AddresseesPerMessage = 10;
StringBuilder builder = new StringBuilder();
String delim = "";
for (ContactItem c:smsMessage.getAddresseeList()) {
// For every phone number in our list
builder.append(delim).append(c.getPhoneNumber().toString());
delim=";";
if (((smsMessage.getAddresseeList().indexOf(c)+1) % AddresseesPerMessage) == 0 || smsMessage.getAddresseeList().indexOf(c)+1 == smsMessage.getAddresseeList().size()) {
// using +1 because index 0 mod 9 == 0
for(String text : smsMessageText){
// Send 160 bytes of the total message until all parts are sent
smsMgr.sendTextMessage(builder.toString(), null, text, sentPI, deliveredPI);
}
builder.setLength(0);
delim="";
}
}
}
This may helpful for you.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.putExtra("address", "5556; 5558; 5560");
// here i can send message to emulator 5556,5558,5560
// you can change in real device
i.putExtra("sms_body", "Hello my friends!");
i.setType("vnd.android-dir/mms-sms");
startActivity(i);
}
});
}
Add this line in AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With