【发布时间】:2011-07-27 20:49:32
【问题描述】:
我正在尝试将 Intent 中的多个附件发送到电子邮件应用程序(而不是 Gmail 应用程序)。我正在使用:
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);
当使用 Gmail 处理 Intent 时,它会显示两个附件,并且一切正常。当使用电子邮件应用程序时,不会添加任何附件。在 EXTRA_STREAM 中使用单个 Uri 时,单个附件有效,但使用 ArrayList 无效。我已经从这里提出的其他问题中拼凑出这段代码,但没有一个能解决这个问题。有人可以帮忙吗?
【问题讨论】:
标签: android email android-intent