Android电子邮件意图不发送附件
我创建了一个发送带有录音的电子邮件的应用程序,当触发意图并选择电子邮件作为发送附件的应用程序时,您可以看到有一个附件,但附件未发送。
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("audio/3gp");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Recording");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileName));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Send email..."));
有什么想法吗?
I have created an application that sends an email with a recording, When the intent is fired and email is chosen as the app to send the attachment, you can see that there is an attachment but the attachment is not delivered.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("audio/3gp");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Recording");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileName));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Send email..."));
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现,你需要确保你的 uri 前面有“file://”。
I figured it out, you need to make sure that your uri has "file://" in front of it.
从 API 级别 24 开始,您不能使用“file://”URI 在包之间传递文件。相反,您应该实现 FileProvider 并使用它传递文件。
FileProvides 的好处是您不需要 WRITE_EXTERNAL_STORAGE 权限(对于 API 级别 21 及以上)。
最好的描述见 另一个 StackOverflow 答案 或该文档。
Starting with API level 24, you cannot use "file://" URIs for passing files between packages. Instead, you should implement FileProvider and pass the file using it.
The good thing about FileProvides is that you don't need WRITE_EXTERNAL_STORAGE permission (for API level 21 and above).
The best description as at another StackOverflow answer or in that documentation.
UriAttachment 不再起作用。您必须使用 FileProvider。但你必须付出一些努力才能使其发挥作用。
该视频完美地解释了它 https://www.youtube.com /watch?v=wYvV4m-N9oY&t=535s[分享 照片和照片使用 FileProvider 的文件]1。
但是,这对我不起作用,我必须做别的事情。我必须将 res/xml/file_paths.xml 替换为:
正如此问题的答案中所述: FileProvider - IllegalArgumentException:无法找到配置的根。您应该仅使用使其工作所需的线路。
我为此奋斗了很长时间,直到找到合适的方法来做到这一点。
UriAttachment does not longer works. You have to use FileProvider. But you have to work a little bit to make it work.
This video explains it perfectly https://www.youtube.com/watch?v=wYvV4m-N9oY&t=535s[Share Photos & Files Using FileProvider]1.
But, it didn´t work for me, I had to do something else. I had to replace res/xml/file_paths.xml with:
As it is described in an answer to this question: FileProvider - IllegalArgumentException: Failed to find configured root. You should use only the lines you need to make it work.
I was fighting a long time with this until I found a proper way to do this.