Android电子邮件意图不发送附件

发布于 2024-09-16 07:26:10 字数 571 浏览 2 评论 0原文

我创建了一个发送带有录音的电子邮件的应用程序,当触发意图并选择电子邮件作为发送附件的应用程序时,您可以看到有一个附件,但附件未发送。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缘字诀 2024-09-23 07:26:10

我发现,你需要确保你的 uri 前面有“file://”。

I figured it out, you need to make sure that your uri has "file://" in front of it.

中二柚 2024-09-23 07:26:10

从 API 级别 24 开始,您不能使用“file://”URI 在包之间传递文件。相反,您应该实现 FileProvider 并使用它传递文件。

Uri fileUri = FileProvider.getUriForFile(context, "com.yourdomain.yourapp.fileprovider", file);

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.

Uri fileUri = FileProvider.getUriForFile(context, "com.yourdomain.yourapp.fileprovider", file);

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.

香草可樂 2024-09-23 07:26:10

UriAttachment 不再起作用。您必须使用 FileProvider。但你必须付出一些努力才能使其发挥作用。

该视频完美地解释了它 https://www.youtube.com /watch?v=wYvV4m-N9oY&t=535s[分享 照片和照片使用 FileProvider 的文件]1

但是,这对我不起作用,我必须做别的事情。我必须将 res/xml/file_paths.xml 替换为:

<?xml version="1.0" encoding="utf-8"?>
   <paths>
     <external-path
        name="external"
        path="." />
    <external-files-path
        name="external_files"
        path="." />
    <cache-path
        name="cache"
        path="." />
    <external-cache-path
        name="external_cache"
        path="." />
    <files-path
        name="files"
        path="." />
</paths>

正如此问题的答案中所述: 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:

<?xml version="1.0" encoding="utf-8"?>
   <paths>
     <external-path
        name="external"
        path="." />
    <external-files-path
        name="external_files"
        path="." />
    <cache-path
        name="cache"
        path="." />
    <external-cache-path
        name="external_cache"
        path="." />
    <files-path
        name="files"
        path="." />
</paths>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文