Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to get a list of files from (a directory on) the sd card?

Tags:

android

I'm happy reading and writing to a pre-set file, and could manually populate a listview, but I'm hoping there is an official(or not) filebrowser I missed, or other more elegant solution to present the user with a directory listing, and let them select a file.

like image 936
Chozabu Avatar asked Sep 15 '10 08:09

Chozabu


2 Answers

final String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File[] files = Environment.getExternalStorageDirectory().listFiles();
} else {
...
}
like image 141
Damian Kołakowski Avatar answered Oct 20 '22 19:10

Damian Kołakowski


File fileList = new File("/sdcard");
if (fileList != null){
    File[] filenames = fileList.listFiles();
        for (File tmpf : filenames){
            //Do something with the files
        }
    }
}

Is another method you can try

like image 34
Kevin Grant Avatar answered Oct 20 '22 18:10

Kevin Grant