Android: ACTION_SEND_MULTIPLE with com.android.email

一曲冷凌霜 提交于 2020-01-03 21:03:19

问题


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?


回答1:


use

emailIntent.setType(" */ * ");

with no spaces

see here ACTION_SEND_MULTIPLE




回答2:


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...




回答3:


Instead of

emailIntent.setType("plain/text");

use

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

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



来源:https://stackoverflow.com/questions/5516738/android-action-send-multiple-with-com-android-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!