简体   繁体   English

从android上的外部存储中获取所有.pdf文件

[英]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);
                }
            }
        }
    }
}

尝试将ContentResolverCursorMediaStore.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.

相关问题 如何在java中从android的可移动存储(SD卡)获取所有pdf文件的链接? - How to get links to all pdf files from removable storage(SD Card) of android in java? 如何在不使用管理外部存储权限的情况下在 android 11 范围存储中获取手机存储中可用的所有 pdf 文件 - how to get all pdf file available in my phone storage in android 11 scope storage without using manage external storage permission 无法从外部存储中获取音频文件 - Android Studio - Can't get audio files from external storage - Android Studio 无法从Android手机的内部和外部存储读取文件 - Unable to read files from internal and external storage of android phone Android - 如何从外部存储读取文本文件 - Android - How can I read text files from external storage 从外部存储中读取特定数量的文件 Android Studio - Read Specific Number of Files From External Storage Android Studio 无法在外部存储Android上编写pdf - Unable to write pdf on External storage Android 将文件从内部存储复制到外部存储 - Copy Files from Internal Storage to external storage 我想从外部存储中获取所有文档文件,但在 android 11 中没有管理存储权限 - i want to get all documents file from external storage with out manage storage permission in android 11 在Android中将文件写入外部存储器失败 - Writing files to external storage in Android failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM