Android 无法从内部目录打开pdf文件
我的位置中有一个pdf文件 /data/user/0/com.app.example/files/user/751f8052e.pdf 现在我想在设备中安装的任何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
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,一切都很正常。谢谢。