Ivan
Ivan

Reputation: 347

How to open a directory saved on SD Card Android

I am programming a notepad android app but I am having difficulties with my Open button. How do i implement it so that when I click on it, a dialog box comes up with the .txt files saved in the folder I created on the SD card? Also, how do i load the chosen file to my current activity?

Thank You

Upvotes: 2

Views: 1701

Answers (1)

Ponmalar
Ponmalar

Reputation: 7031

Try the Following,

File f = new File(Environment.getExternalStorageDirectory() +"/"+ dirname);
if(f.isDirectory())
{
    ArrayList<String> files= new ArrayList<String>();
    File file = new File(Environment.getExternalStorageDirectory() +"/"+ dirname+"/");
    File fileList[] = file.listFiles();
    for(int i=0;i<fileList.length;i++)
    {
        files.add(filelist[i].getAbsolutePath());
        //here you can get all files.
    }
}

Upvotes: 4

Related Questions