Ale*_*lex 5 pdf android android-7.0-nougat
我有一个文件路径:file:///storage/emulated/0/Android/data/rocks.v d.*****.develop/files/1Q 2017财务结果.pdf
这是代码:
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
String newFilePath = filePath.replaceAll("%20", " ");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
intent.setDataAndType(Uri.parse(newFilePath), "application/pdf");
} else {
Uri uri = Uri.parse(newFilePath);
File file = new File(uri.getPath());
if (file.exists()){
uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
intent.setDataAndType(uri, "application/pdf");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我的uri = content://rocks.v d.*****.develop.provider/files/Android/data/rocks.v d.*****.develop/files/1Q%202017%20financial%20results .PDF
Pdf阅读器打开时出现意外错误.怎么了?
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Run Code Online (Sandbox Code Playgroud)
在这里,你要消灭所有现有的旗帜,特别是你的旗帜FLAG_GRANT_READ_URI_PERMISSION.因此,您启动的活动将无法访问您的内容.
切换setFlags()到addFlags().
| 归档时间: |
|
| 查看次数: |
3980 次 |
| 最近记录: |