Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法从内部目录打开pdf文件_Android_Pdf_Android Fileprovider - Fatal编程技术网

Android 无法从内部目录打开pdf文件

Android 无法从内部目录打开pdf文件,android,pdf,android-fileprovider,Android,Pdf,Android Fileprovider,我的位置中有一个pdf文件 /data/user/0/com.app.example/files/user/751f8052e.pdf 现在我想在设备中安装的任何PDF阅读器上打开此文件 这就是我目前正在做的 Uri imageUri ; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { imageUri = FileProvider.getUriForFile(context , context.ge

我的位置中有一个pdf文件

/data/user/0/com.app.example/files/user/751f8052e.pdf

现在我想在设备中安装的任何PDF阅读器上打开此文件

这就是我目前正在做的

Uri imageUri ;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
    imageUri = FileProvider.getUriForFile(context , context.getString(R.string.file_provider_authority), PDFFile);
}
else
{
    imageUri = Uri.fromFile(PDFFile);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_VIEW);
shareIntent.setDataAndType(imageUri , "application/pdf");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(shareIntent);
但它并没有打开pdf文件。它出了一个错误

无法打开该文件

注意:我无法将文件复制到其他目录


感谢指定的私有目录,您应该始终使用文件提供商。

是用于if还是else?为什么您无法复制该文件?@greenapps For the elseyes,这是完全正确的。我刚刚删除了if,一切都很正常。谢谢。