在android上的目录中过滤apk文件

时间:2016-07-27 14:14:25

标签: android

private class ExtensionFilenameFilter implements FilenameFilter {

    private String[] Extensions;

    public ExtensionFilenameFilter(String[] extensions) {

        super();
        Extensions = extensions;
    }

    public boolean accept(File dir, String filename) {

        if (new File(dir, filename).isDirectory()) {

            // Accept all directory names
            return true;
        }

        if (Extensions != null && Extensions.length > 0) {

            for (int i = 0; i < Extensions.length; i++) {

                if (filename.endsWith(".apk")) {

                    // The filename ends with the extension
                    return true;
                }
            }
            // The filename did not match any of the extensions
            return false;
        }
        // No extensions has been set. Accept all file extensions.
        return true;
    }
}

我想要查看仅包含.apk个扩展名的文件。

怎么做?请清楚说明源代码。

1 个答案:

答案 0 :(得分:0)

很简单:

private class ExtensionFilenameFilter implements FilenameFilter {

    public boolean accept(File dir, String filename) {
        return filename.endsWith(".apk");
    }
}