如何找到具有一定的扩展Android上的所有文件? [英] How to find all files with certain extension on Android?

查看:96
本文介绍了如何找到具有一定的扩展Android上的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是fileBrowser找到手机上的文件,但是我想表明,我的应用程序可以打开该用户的所有文件,然后用户选择之一。像音乐播放器,即显示出的所有歌曲在电话上的SD卡和在内部存储器中,不仅那些在文件夹中,其中用户是

I'm using a fileBrowser to find the files on the phone, but I wanted to show all files that my app can open to the user, and then the user chooses one. Like the Music Player, that show all songs on phone, on the sdcard and in the internal memory, not only the ones in the folder where the user is.

推荐答案

使用文件名过滤器,同时列出了这些文件。下面的示例列出了所有的MP3文件在给定的目录(注 - 低于code没有在根) -

Use file name filters while listing out the files. The below sample lists out all mp3 files in a given root directory (Note - The below code doesn't do it recursively for all folders under root) -

String files[] = root.list(audioFilter);

FilenameFilter audioFilter = new FilenameFilter() {
    File f;
    public boolean accept(File dir, String name) {
    if(name.endsWith(".mp3") || name.endsWith(".MP3")) {
            return true;
        }
        f = new File(dir.getAbsolutePath()+"/"+name);

        return f.isDirectory();
    }
};

这篇关于如何找到具有一定的扩展Android上的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆