gpt4 book ai didi

java - 如何从SD卡打开pdf

转载 作者:搜寻专家 更新时间:2023-11-01 09:20:45 24 4
gpt4 key购买 nike

尝试从设备上的下载文件夹中打开 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com