Reputation: 2072
Im writing an app that sends an SMS to several contacts. The contacts numbers are stored in an ArrayList
(was received from another activity). I am not able to use this ArrayList
to pass several contacts to the built-in SMS android app. This is the code:
ArrayList<String> numbersArrayList=getIntent().getExtras().getStringArrayList("phoneNumbers");
String message= "this is a custom message";
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", message);
smsIntent.putExtra("address", ??????????);
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
I can iterate and print these contacts to the LogCat the simple "for each" loop and overriding toString method.
Upvotes: 3
Views: 9518
Reputation: 2681
Use this code..
String toNumbers = "";
for ( String s : numbersArrayList)
{
toNumbers = toNumbers + s + ";"
}
toNumbers = toNumbers.subString(0, toNumbers.length - 1);
String message= "this is a custom message";
Uri sendSmsTo = Uri.parse("smsto:" + toNumbers);
Intent intent = new Intent(
android.content.Intent.ACTION_SENDTO, sendSmsTo);
intent.putExtra("sms_body", message);
startActivity(intent);
Upvotes: 9