Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send SMS through intent to multiple phone numbers

Tags:

android

sms

When i sending the sms through Intent an exception comes android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO typ=vnd.android-dir/mms-sms (has extras) }

See my code below:-

try {

                 Intent sendIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:5551212;5551212"));
                 sendIntent.putExtra("sms_body", sendSMSStringOnCustomCheckIn()); 
                 sendIntent.setType("vnd.android-dir/mms-sms");
                 startActivity(sendIntent);

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                    "SMS faild, please try again later!",
                    Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }

I want to send the SMS to 2 phone nembers and both the phone numbers should be display in the recipient box of default SMS box.How can i do that?

like image 454
Deepak Sharma Avatar asked Dec 26 '22 20:12

Deepak Sharma


1 Answers

I got the solution of my Question. In SAMSUNG devices i have to separate the phone numbers with ',' while other devices are accept the ';'.So unfortunately have to do this ugly vendor specific decision within your source code.

 String separator = "; ";


 if(android.os.Build.MANUFACTURER.equalsIgnoreCase("Samsung")){
    separator = ", ";
  }

Now my below code is working properly for SAMSUNG devices.

try {

                 Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                 sendIntent.putExtra("address", "9971227563,9990900909");
                 sendIntent.putExtra("sms_body", sendSMSStringOnCustomCheckIn());
                 sendIntent.setType("vnd.android-dir/mms-sms");
                 startActivity(sendIntent);

            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                    "SMS faild, please try again later!",
                    Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
like image 154
Deepak Sharma Avatar answered Dec 28 '22 09:12

Deepak Sharma