我正在尝试将图像附加到电子邮件消息中,但是当本地电子邮件客户端打开时,图像并未附加。
Gmail 客户端显示无法附加文件消息。
雅虎电子邮件客户端没有显示警告,但也没有附加图像。
我使用配备 Android 7.0 的 Lenovo K6 设备进行测试。
这是我用来将图像附加到电子邮件的代码:
Message m = new Message(content);
m.getAttachments().put(imgUri, "image/png");
也尝试过“image/jpeg”,但无济于事。
文件 URI 如下所示:
file:///storage/emulated/0/DCIM/Camera/IMG_20171015_170852.jpg
我什至尝试将图像移动到 FileSystemManager.getInstance().getAppHomePath()
下的位置
但还是没成功。
即使我使用 Capture 对象创建新图像或从图库中选择现有图像,结果也是相同的。但是,如果我从电子邮件客户端内部手动附加图像,一切都会按预期进行。
Android 日志没有多大帮助。
10-20 12:14:15.695 32049 32049 E Gmail : Error adding attachment
10-20 12:14:15.695 32049 32049 E Gmail : dsh: Failed to create local attachment
10-20 12:14:15.695 32049 32049 E Gmail : at dsi.a(SourceFile:132)
10-20 12:14:15.695 32049 32049 E Gmail : at cmd.a(SourceFile:1840)
10-20 12:14:15.695 32049 32049 E Gmail : at cmp.run(SourceFile:4)
10-20 12:14:15.695 32049 32049 E Gmail : at cmd.a(SourceFile:665)
10-20 12:14:15.695 32049 32049 E Gmail : at cmd.a(SourceFile:422)
10-20 12:14:15.695 32049 32049 E Gmail : at cmd.N(SourceFile:536)
10-20 12:14:15.695 32049 32049 E Gmail : at cmd.onCreate(SourceFile:181)
10-20 12:14:15.695 32049 32049 E Gmail : at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:40)
我已经没有选择了。 请问有什么建议吗?
最佳答案
您添加的附件不正确。 getAttachments()
用于返回现有文件 URI 和 mime 类型对,这不是添加附件的最佳方式。
试试这个:
m.setAttachment(imgUri);
m.setAttachmentMimeType(Message.MIME_IMAGE_PNG);
此外,请检查 URI 路径并确保其正确,因为我可以看到此 file:///
。
我还建议您将该文件放置在应用程序主目录中。
关于android - 代号一 : Attaching images to email message fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46846369/