[英]Getting all .pdf files from External storage on android
I'm trying to get all pdf's recursively from the External storage. 我试图从外部存储中递归获取所有pdf。 What I'd like to have, is an interface just like pdf reader's, meaning, that it loads the files asynchronously and displays each directory name in a separator.
我想拥有的是一个类似pdf阅读器的界面,意思是它以异步方式加载文件并在分隔符中显示每个目录名称。 I've got the separator part down, but now I need the loading.
我有分离器部件,但现在我需要加载。
Any tips on doing this? 这样做的任何提示? I know that I should just iterate through all files, check if the files is a directory and launch the recursive algorithm again, but how to write this to only show .pdf files?
我知道我应该遍历所有文件,检查文件是否是目录并再次启动递归算法,但是如何将其写入仅显示.pdf文件?
private static void searchFolderRecursive1(File folder) {
if (folder != null) {
if (folder.listFiles() != null) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
if(file.getName().contains(".pdf")){
Log.v("ooo", "path__="+file.getName());
}
} else {
searchFolderRecursive1(file);
}
}
}
}
}
尝试将ContentResolver与Cursor和MediaStore.Files.FileColumns.MIME_TYPE一起用作“pdf”。
I know that I should just iterate through all files, check if the files is a directory and launch the recursive algorithm again, but how to write this to only show .pdf files?
我知道我应该遍历所有文件,检查文件是否是目录并再次启动递归算法,但是如何将其写入仅显示.pdf文件?
Look at the file name and see if it ends in .pdf
, possibly using a FilenameFilter
, as shown here . 看看文件名,看它是否在结束
.pdf
,可能使用FilenameFilter
,如图所示这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.