我想打开PDF格式,这是interaly保存在应用程序/资产/ pdf_name.pdf从资产中分享PDF。 FileUriExposedException
我得到使用 File f = new File(getContext().getCacheDir() + /pdf_name.pdf");
我试图提取URI文件如果内容形式: //使用
Uri pdfUri = FileProvider.getUriForFile(getContext(), "pcg_name.fileprovider", file);
,但我得到了
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/pck_name/cache/pdf_name.pdf
ALthout我可配置
<paths>
<cache-path
name="my_documents"
path="assets/"/>
<cache-path
name="my_pdf"
path="cache/"/>
</paths>
我的目标是通过意向来打开PDF,但我不能只是做:因为它抛出文件URI暴露例外
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(pdfFile),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // DON'T FORGET this
你save'd我的一天。我很接近,因为当我第一次输入姓名时,Android Studio强调错误:它应该包含路径,所以我放弃了这个想法。然而它编译,毕竟作品。 – murt