【发布时间】:2018-12-21 18:09:15
【问题描述】:
我尝试使用以下代码通过 gmail 发送带有附件的邮件:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "test@mail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "test Mail");
File file = ..function that return file with logs...
File newFile = new File(getFilesDir() + File.separator + "logs" + File.separator + System.currentTimeMillis() + ".log");
FileTools.fileCopy(file, newFile);
Uri uri = FileProvider.getUriForFile(this,
"test.test.test.provider", newFile);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivityForResult(Intent.createChooser(emailIntent, "eMail"), 1);
我还添加了文件夹日志的路径
<files-path name="logs" path="logs/" />
它运行带有 toast 的 gmail 应用程序“无法附加文件”。 在调试 uri 变量中看起来:
content://test.test.test.provider/logs/1545415598572.log
当我改变时
Uri uri = FileProvider.getUriForFile(this, "test.test.test.provider", newFile);
与
Uri uri = Uri.uri(newFile);
它只适用于外部存储中的文件。
为什么它不适用于 FileProvider?
【问题讨论】:
-
您是否在 Android Manifest 文件中创建了提供程序?
-
是的,我看到 FileProvider 它在项目中的其他地方使用过,它可以正常工作,所以它是正确的。
-
稍等片刻,我将展示我的示例我是如何做到的。也许它会帮助你。