我正在使用此代码附加文件:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
String uriText;
Uri file = Uri.fromFile(new File(path));
uriText = "mailto:" +
"?subject=the subject" +
"&body=the body of the message"+
"&attachment="+file;
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
emailIntent.setData(uri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
(请注意,path
类似于“/sdcard/test.jpg”,我使用了 ACTION_SENDTO
,因为我只想在选择器中查看电子邮件应用程序.)
Intent 将提供电子邮件应用程序列表,但附件不会出现在电子邮件或 Gmail 中。如何让附件显示?
最佳答案
这似乎适用于我的 Galaxy Nexus 和 Nexus 4(均运行标准的 JellyBean API 17)。
具体来说:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "email@me.com", null));
intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(attachmentFile));
startActivity(Intent.createChooser(intent, "Send email..."));
这不适用于我的 Nexus One (Gingerbread API 10) 或更旧的设备。我不确定它是从什么时候开始起作用的。
也许其他人对此有更多详细信息?
当 ACTION_SENDTO 不合适时:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "email@me.com" });
intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(attachmentFile));
关于android - 使用 `mailto:` 方案通过 Intent 发送电子邮件附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12741865/