作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
尝试从设备上的下载文件夹中打开 pdf 文件,我将文件名保存在 firebase
中,现在我想检查该文件是否已在设备上找到,然后打开它,否则从 firebase
下载。
File file = new File(Environment.getExternalStorageDirectory() + "filename");
System.out.println(Environment.getExternalStorageDirectory());
///but when i print Environment.getExternalStorageDirectory() i get
///storage/emulated/0
if (file.exists()) {
System.out.println(file.getAbsoluteFile());
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file), "application/pdf");
target = Intent.createChooser(target, "Open File");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
} else {
System.out.println("file not found");
}
最佳答案
试试这个从下载目录中获取你的文件
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + filename);
关于java - 如何从SD卡打开pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55915507/
我是一名优秀的程序员,十分优秀!