文件提供者在android Nougat中显示空白
我在设备的内部存储器中有一个pdf文件,位置为“/storage/emulated/0/MyPdf/test.pdf”。当使用FileProvider访问它时,pdf阅读器是用黑色填充的空白。 路径文件如下所示文件提供者在android Nougat中显示空白,android,pdf,Android,Pdf,我在设备的内部存储器中有一个pdf文件,位置为“/storage/emulated/0/MyPdf/test.pdf”。当使用FileProvider访问它时,pdf阅读器是用黑色填充的空白。 路径文件如下所示 我的代码中的java代码片段是 File pdfFile = new File(Environment.getExternalStorageDirectory() + "/MyPdf/" + "test.pdf"); Uri path = FileProvider.get
我的代码中的java代码片段是
File pdfFile = new File(Environment.getExternalStorageDirectory() + "/MyPdf/" + "test.pdf");
Uri path = FileProvider.getUriForFile(getContext(),"com.test.pdf.fileprovider", pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
startActivity(pdfIntent);
}catch(ActivityNotFoundException e){
Toast.makeText(getContext(), "No Application available to view PDF", Toast.LENGTH_SHORT).show();
}
我的清单文件中的提供程序
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.test.pdf.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
请帮助我解决此问题替换:
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
与:
由于您不需要
FLAG\u ACTIVITY\u CLEAR\u TOP
,但您肯定需要FLAG\u GRANT\u READ\u URI\u PERMISSION
,.getUriForFile()的第二个参数不应该是您在清单文件中提到的权限吗
"com.test.pdf.fileprovider" instead of ""com.visakh.horizon.horizon.fileprovider"
很抱歉,复制代码时出错。两者都一样。现在我在问题中改变了它
"com.test.pdf.fileprovider" instead of ""com.visakh.horizon.horizon.fileprovider"