【发布时间】:2013-12-14 07:58:11
【问题描述】:
我有一个关于 android FileProvider 的问题。 我想保存一个 pdf 文档并使用默认程序打开它。 我不想将它保存在外部存储中。
在我成功将 pdf 保存到 FilesDirectory/export/temp.pdf 后,
我尝试使用 FileProvider.getUriForFile() 生成 URI。
File path = new File(getFilesDir(), "export");
File pdf = new File(path + File.separator + "temp.pdf");
pdf.getParentFile().mkdirs();
if (!pdf.exists())
pdf.createNewFile();
Uri uri = FileProvider.getUriForFile(getApplicationContext(), "?", pdf);
问题:我必须传递什么作为第二个参数“权限” - 我的文件的位置、可以授予 URI-Permissions 的类或其他什么?无论我尝试过什么都会导致 IllegalArgumentException 或 NullPointerException。 我的文件提供者(XML):
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.myApp.myActivity"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path"/>
</provider>
参考文件:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="pdfTemplates" path="export/" />
</paths>
【问题讨论】:
-
我也有同样的问题。你找到答案了吗?
标签: pdf authority android-fileprovider