I want my app to share data with multiple people. Ideally I'd like for the user to be able to select a contact group, and it would launch an intent to share that data with everyone in the contact group, e.g. Open Gmail with the address field populated with that group of users' email addres开发者_StackOverflow中文版ses. Is this possible using an ACTION_SENDTO
Intent? I can't even find an example of how to use it to send to one person, let alone multiple yet.
Using ACTION_SEND
and Intent.EXTRA_EMAIL
will not limit the app chooser to email apps only. Instead, use ACTION_SENDTO
, as in:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
emailIntent.setType("message/rfc822");
emailIntent.setData(Uri.parse("mailto:first.mail@gmail.com,second.mail@gmail.com"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "email content");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
As seen in the example, you can send an email to multiple recipients by comma-separating the Uri. There is no need to catch ActivityNotFoundException
from startActivity(..)
, as the android framework will handle it for you an show an appropriate message to the user.
If you want the format the email in html, you can use:
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<i>my html-formatted text!</i>"));
I hope you have used the following statement in your code
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"user@example.com"});
it accepts String array, you can pass multiple recipient name over there
You can use Intent.ACTION_SEND_MULTIPLE
as an action for email launching intent for sending data to multiple recipients.
create a list of email ids and use it against Intent.EXTRA_EMAIL
key, as this will include all emails from email-list in to field of send email form.
How about this code:
final Intent emailLauncher = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailLauncher.setType("message/rfc822");
emailLauncher.putExtra(Intent.EXTRA_EMAIL, emailList);
emailLauncher.putExtra(Intent.EXTRA_SUBJECT, "check this subject line");
emailLauncher.putExtra(Intent.EXTRA_TEXT, "hey check this message body!");
try{
startActivity(emailLauncher);
}catch(ActivityNotFoundException e){
}
精彩评论