문제

public static final String paths = "/storage/" ;

public ArrayList<HashMap<String, String>> getpaths(){
    if (paths != null) {
        File x= new File(paths);
        File[] listFiles = x.listFiles();
        if (listFiles != null && listFiles.length > 0) {
            for (File file : listFiles) {

                if (file.isDirectory()) { 
                    scanDirectory(file);  
                } else {
                    fileFilter(file); 
                }
            }
        }
    }

That is my function to list files from /storage.

My question is: do all android phones have /storage/a/b/c ?

도움이 되었습니까?

해결책

No, folder hierarchy is same but root of sd-card can be mounted somewhere else and your program would not work. Use:

File paths = Environment.getExternalStorageDirectory();

to get root of sd-card and your program will work on all phones.

EDIT: For example I have CM 11 ROM and Kernel which uses different layout than on other phones.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top