Reputation: 628
I am developing an Android application in which I am sending multiple attachments to email client application. To send multiple attachments I am using ACTION_SEND_MULTIPLE intent.
Code snippet:
Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Test"); // email subject
ArrayList<CharSequence> msg = new ArrayList<CharSequence>();
msg.add(mail_body); // email body
emailIntent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, msg);
ArrayList<Uri> uris = new ArrayList<Uri>(); //attachments
uris.add(Uri.fromFile(logFile));
uris.add(Uri.fromFile(oldLogFile));
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
this.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), ErrorCodes.MAIL_ACTIVITY);
Output of the above code:
In the Gmail application, the attachments are present but email body is missing.
How can I fix this issue? I would appreciate any suggestions and thought on this topic.
Upvotes: 0
Views: 873
Reputation: 1006869
First, ACTION_SEND_MULTIPLE
does not use a Uri
, as you have with your setData()
call.
Second, ACTION_SEND_MULTIPLE
uses either EXTRA_TEXT
or EXTRA_STREAM
, not both. See the documentation. This is the most likely source of your difficulty — you are trying to do something that is not documented to work.
Third, Uri.fromFile()
will not work on Android 7.0+, if your app has a targetSdkVersion
of 24 or higher. You will need to use FileProvider
or some similar solution.
Upvotes: 1