2

I've been stumped on this for the past few days. I'm trying to read the folders I have in my SD card when I click a button.

When I run my code, logcat gives me: D/EH: Directory: /storage/emulated/0 but I'm pretty sure that's my internal memory. And even so, it doesn't list any of my folders or files in what I'm guessing my internal directory. I'm about to give up on finding my sd location and just hard code it for the time being. If I was to do that, how would I find out my external location?

public void onClickBtn(View v) {
    final String state = Environment.getExternalStorageState();

    if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) {  // we can read the External Storage...
        getAllFilesOfDir(Environment.getExternalStorageDirectory());
    }
}

private void getAllFilesOfDir(File directory) {
    Log.d("EH", "Directory: " + directory.getAbsolutePath() + "\n");

    final File[] files = directory.listFiles();

    if ( files != null ) {
        for ( File file : files ) {
            if ( file != null ) {
                if ( file.isDirectory() ) {  // it is a folder...
                    getAllFilesOfDir(file);
                }
                else {  // it is a file...
                    Log.d("EH", "File: " + file.getAbsolutePath() + "\n");
                }
            }
        }
    }
}

Thanks for the help!

Pam
  • 399
  • 2
  • 16

0 Answers0