我正在使用此代码附加文件:
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
因为我只想在选择器中看到电子邮件应用程序。)
该意图将提供电子邮件应用程序列表,但附件不会出现在电子邮件或 Gmail 中。如何才能显示附件?
这似乎适用于我的 Galaxy Nexus 和 Nexus 4(均运行 Stock JellyBean API 17)。
具体来说:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "[email protected] /cdn-cgi/l/email-protection", 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 protected] /cdn-cgi/l/email-protection" });
intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(attachmentFile));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)