In Android is it possible to send sms message to more than one recipient in code?

Here I am attaching source code what I have done to send message programatically SMS: public class SMS extends Activity { Button btnSendSMS; EditText txtPhoneNo; EditText txtMessage; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout.

Main); btnSendSMS = (Button) findViewById(R.id. BtnSendSMS); txtPhoneNo = (EditText) findViewById(R.id. TxtPhoneNo); txtMessage = (EditText) findViewById(R.id.

TxtMessage); btnSendSMS. SetOnClickListener(new View.OnClickListener() { public void onClick(View v) { String message = txtMessage.getText().toString(); String phoneNo = txtPhoneNo.getText().toString(); StringTokenizer st=new StringTokenizer(phoneNo,","); while (st.hasMoreElements()) { String tempMobileNumber = (String)st.nextElement(); if(tempMobileNumber.length()>0 && message.trim().length()>0) { sendSMS(tempMobileNumber, message); } else { Toast. MakeText(getBaseContext(), "Please enter both phone number and message.", Toast.

LENGTH_SHORT).show(); } } // if (phoneNo.length()>0 && message.length()>0) // sendSMS(phoneNo, message); // else // Toast. MakeText(getBaseContext(), // "Please enter both phone number and message.", // Toast. LENGTH_SHORT).show(); } }); } private void sendSMS(String phoneNumber, String message) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI = PendingIntent.

GetBroadcast(this, 0, new Intent(SENT), 0); PendingIntent deliveredPI = PendingIntent. GetBroadcast(this, 0, new Intent(DELIVERED), 0); //---when the SMS has been sent--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity. RESULT_OK: Toast.

MakeText(getBaseContext(), "SMS sent", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_GENERIC_FAILURE: Toast.

MakeText(getBaseContext(), "Generic failure", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_NO_SERVICE: Toast.

MakeText(getBaseContext(), "No service", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_NULL_PDU: Toast.

MakeText(getBaseContext(), "Null PDU", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_RADIO_OFF: Toast.

MakeText(getBaseContext(), "Radio off", Toast. LENGTH_SHORT).show(); break; } } },new IntentFilter(SENT)); //---when the SMS has been delivered--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity. RESULT_OK: Toast.

MakeText(getBaseContext(), "SMS delivered", Toast. LENGTH_SHORT).show(); break; case Activity. RESULT_CANCELED: Toast.

MakeText(getBaseContext(), "SMS not delivered", Toast. LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); sms. SendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } } SmsReceiver: public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage msgs = null; String str = ""; if (bundle!

= null) { //---retrieve the SMS message received--- Object pdus = (Object) bundle. Get("pdus"); msgs = new SmsMessagepdus. Length; for (int i=0; iCreateFromPdu((byte)pdusi); str += "SMS from " + msgsi.

GetOriginatingAddress(); str += " :"; str += msgsi.getMessageBody().toString(); str += "\n"; } //---display the new SMS message--- Toast. MakeText(context, str, Toast. LENGTH_SHORT).show(); } } } and need to set permission in manifest to READ_SMS,RECIEVE_SMS.

This is how you can send message to single user This is how you can send message to multiple user. ........................................... Suppose you need to send message to multiple user you can write number separated by comma for eg.5558,5554 This is how you can separate two numbers separated by comma using String tokenizer class used in the above code You can apply this logic where you are calling SendSms Function and pass appropiate phone number each time It works fine for me..u can try it out.. Is it answer your question? Thanks Rakesh.

Here I am attaching source code what I have done to send message programatically. SMS: public class SMS extends Activity { Button btnSendSMS; EditText txtPhoneNo; EditText txtMessage; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); setContentView(R.layout. Main); btnSendSMS = (Button) findViewById(R.id. BtnSendSMS); txtPhoneNo = (EditText) findViewById(R.id.

TxtPhoneNo); txtMessage = (EditText) findViewById(R.id. TxtMessage); btnSendSMS. SetOnClickListener(new View.OnClickListener() { public void onClick(View v) { String message = txtMessage.getText().toString(); String phoneNo = txtPhoneNo.getText().toString(); StringTokenizer st=new StringTokenizer(phoneNo,","); while (st.hasMoreElements()) { String tempMobileNumber = (String)st.nextElement(); if(tempMobileNumber.length()>0 && message.trim().length()>0) { sendSMS(tempMobileNumber, message); } else { Toast.

MakeText(getBaseContext(), "Please enter both phone number and message. ", Toast. LENGTH_SHORT).show(); } } // if (phoneNo.length()>0 && message.length()>0) // sendSMS(phoneNo, message); // else // Toast.

MakeText(getBaseContext(), // "Please enter both phone number and message. ", // Toast. LENGTH_SHORT).show(); } }); } private void sendSMS(String phoneNumber, String message) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI = PendingIntent.

GetBroadcast(this, 0, new Intent(SENT), 0); PendingIntent deliveredPI = PendingIntent. GetBroadcast(this, 0, new Intent(DELIVERED), 0); //---when the SMS has been sent--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity. RESULT_OK: Toast.

MakeText(getBaseContext(), "SMS sent", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_GENERIC_FAILURE: Toast.

MakeText(getBaseContext(), "Generic failure", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_NO_SERVICE: Toast.

MakeText(getBaseContext(), "No service", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_NULL_PDU: Toast.

MakeText(getBaseContext(), "Null PDU", Toast. LENGTH_SHORT).show(); break; case SmsManager. RESULT_ERROR_RADIO_OFF: Toast.

MakeText(getBaseContext(), "Radio off", Toast. LENGTH_SHORT).show(); break; } } },new IntentFilter(SENT)); //---when the SMS has been delivered--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity. RESULT_OK: Toast.

MakeText(getBaseContext(), "SMS delivered", Toast. LENGTH_SHORT).show(); break; case Activity. RESULT_CANCELED: Toast.

MakeText(getBaseContext(), "SMS not delivered", Toast. LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); sms. SendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } } SmsReceiver: public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage msgs = null; String str = ""; if (bundle!

= null) { //---retrieve the SMS message received--- Object pdus = (Object) bundle. Get("pdus"); msgs = new SmsMessagepdus. Length; for (int i=0; iLength; i++) { msgsi = SmsMessage.

CreateFromPdu((byte)pdusi); str += "SMS from " + msgsi. GetOriginatingAddress(); str += " :"; str += msgsi.getMessageBody().toString(); str += "\n"; } //---display the new SMS message--- Toast. MakeText(context, str, Toast.

LENGTH_SHORT).show(); } } } and need to set permission in manifest to READ_SMS,RECIEVE_SMS. This is how you can send message to single user.. This is how you can send message to multiple user............................................ Suppose you need to send message to multiple user you can write number separated by comma for eg.5558,5554. This is how you can separate two numbers separated by comma using String tokenizer class used in the above code You can apply this logic where you are calling SendSms Function and pass appropiate phone number each time It works fine for me..u can try it out.. Is it answer your question?

Thanks Rakesh.

Roman I have done app with this able to send msg to multiple emulator...You can try it out..it will work, and write numbers separated by comma eg. 5556,5558.... – Rakesh Gondaliya Sep 1 '10 at 4:19 1 Thanks man, this works great! – roman Sep 3 '10 at 14:42 hi Roman,R you satisfied with the Answer I have posted,Is it able to work for u,IS it your Accepted answer, or do need some more help I will be happy to help..Thanks. Rakesh – Rakesh Gondaliya Sep 4 '10 at 4:42 hai rakesh thanks for the above code.

While sending sms to multiple numbers using this code we can get resultcode of every number. But for which number I am getting the result code iam unable to catch that. For example I am sending sms to 1 10digit number and other 7 digit number.

I am getting 2 resultcodes one resultok and other genericfailure. For what number iam getting resultok and for what number iam getting genericfailure iam unable to get.. hope you understood. Please clarify my doubt.. – Sando Aug 18 at 11:05.

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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions