Android: ACTION_SEND_MULTIPLE with com.android.ema

2019-07-03 16:02发布

I'm trying to send multiple attachments in an Intent to the Email app (not the Gmail app). I'm using:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "sample@email.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"This is an email");
emailIntent.putExtra(Intent.EXTRA_TEXT, "This is the body");

File f1 = null;
File f2 = null;
try {
    f1 = new File("/sdcard/test");
    f2 = new File("/sdcard/test.1");
    FileWriter fw1 = new FileWriter(f1);
    FileWriter fw2 = new FileWriter(f2);
    fw1.write("this is some text");
    fw2.write("this is more text");
    fw1.close();
    fw2.close();
} catch (IOException e) {
    e.printStackTrace();
}

ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.fromFile(f1));
uris.add(Uri.fromFile(f2));
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);

startActivity(emailIntent);

When Gmail is used to handle the Intent, it comes up with both attachments showing, and everything works just fine. When the Email app is used instead, no attachments are added. When using a single Uri in EXTRA_STREAM, the single attachment works, but using an ArrayList does not. I've pieced together this code from other questions asked on here, but none of them resolve this issue. Can anyone help?

3条回答
对你真心纯属浪费
2楼-- · 2019-07-03 16:44

use

emailIntent.setType(" */ * ");

with no spaces

see here ACTION_SEND_MULTIPLE

查看更多
闹够了就滚
3楼-- · 2019-07-03 16:44

I realize that this is quite late, but your intent type is backwards. It should be

emailIntent.setType("text/plain");

not

emailIntent.setType("plain/text");

I'm surprised neither of the other answers pointed that out...

查看更多
来,给爷笑一个
4楼-- · 2019-07-03 16:46

Instead of

emailIntent.setType("plain/text");

use

emailIntent.setType("application/octet-stream");

I don't know why, but it's working for me.

查看更多
登录 后发表回答