【发布时间】:2021-12-03 11:45:14
【问题描述】:
我几乎找到了许多类似的链接 - 没有任何帮助
- Gmail 不允许我从 /storage/emulated/0/Android/data/myapppackage/cache/..pdf 手动使用 Gmail 和以编程方式获取文件
- 如果将相同的文件下载到 /storage/emulated/0/download/..pdf,则可以附加
代码 -
protected void sendEmail(Context ctx, String filePath){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = Uri.fromfile(new File(filePath)));
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "PDF"));
ctx.startActivity(emailIntent);
}
file_provder.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="/" />
<files-path name="files" path="/" />
</paths>
尝试了以下链接,它几乎看起来很完美,但对我不起作用 - Attaching cache file to GMail through FileProvider and Intent not working
【问题讨论】:
-
如果你不使用它,发布 file_provider.xlm 是没有意义的。使用 FileProvider 获取 uri 而不是 Uri.fromFile()。
-
请调整您的代码并开始显示分配给
filePath的值。 -
Gmail is not allowing me如果您应该使用 FileProvider,那么 Gmail 会看到一个 uri。它一开始就看不到这样的路径。它不知道文件来自哪里。如果您使用 FileProvider,Gmail 不需要任何访问权限。 -
感谢@blackapps 的建议,从fileprovider 获取url 后就可以了
标签: android pdf gmail android-12 android-api-31