Saturday, February 11, 2012

How to view all files from sdcard in android device?

This is a little code snippet that i developed recently when i wanted to build an "android file manager".You can see all the files form sdcard using this code snippet.

    File file[] = Environment.getExternalStorageDirectory().listFiles();
recursiveFileFind(file);


public void recursiveFileFind(File[] file1){
    int i = 0;
    String filePath="";
         if(file1!=null){
        while(i!=file1.length){
            filePath = file1[i].getAbsolutePath();
        if(file1[i].isDirectory()){
        File file[] = file1[i].listFiles();
                recursiveFileFind(file);
        }
            i++;
            //Log.d(i+"", filePath);
        }
      }
    }

No comments:

Post a Comment