使用“mailto:”方案通过意图发送电子邮件附件 [英] E-mail attachment through intent using `mailto:` scheme

查看:191
本文介绍了使用“mailto:”方案通过意图发送电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  final Intent emailIntent = new Intent(android.content.Intent .ACTION_SENDTO); 
String uriText;
Uri file = Uri.fromFile(new File(path));
uriText =mailto:+
?subject =主题+
& body =消息正文+
& attachment =+文件;
uriText = uriText.replace(,%20);
Uri uri = Uri.parse(uriText);
emailIntent.setData(uri);
startActivity(Intent.createChooser(emailIntent,Send mail ...));

(请注意,路径 /sdcard/test.jpg,我使用 ACTION_SENDTO ,因为我只想在选择器中看到电子邮件应用程序。)



意图将提供电子邮件应用程序列表,但附件不会显示在电子邮件或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,发送电子邮件...));

这不适用于我的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));


I'm using this code to attach a file:

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..."));

(Note that path is something like "/sdcard/test.jpg" and that I used ACTION_SENDTO because I just want to see e-mail apps in the chooser.)

The intent will provide a list of e-mail applications, but the attachment doesn't appear in Email or Gmail. How can I get the attachment to display?

解决方案

This seems to work on my Galaxy Nexus and Nexus 4 (both running stock JellyBean API 17).

Specifically:

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..."));

This does NOT work on my Nexus One (Gingerbread API 10) or older devices. I'm not sure at what point it started working.

Maybe someone else has some more details on this?

When ACTION_SENDTO is not appropriate:

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));

这篇关于使用“mailto:”方案通过意图发送电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆