Here you can get the list of folders from the memory card:
String state = Environment.getExternalStorageState(); if(state.contentEquals(Environment.MEDIA_MOUNTED) || state.contentEquals(Environment.MEDIA_MOUNTED_READ_ONLY)) { String homeDir = Environment.getExternalStorageDirectory(); File file = new File(homeDir); File[] directories = file.listFiles(); } else { Log.v("Error", "External Storage Unaccessible: " + state); }
This code is from the top of my head, so some syntax may be a bit, but the general idea should work. You can use something like this to filter folders only in folders containing images:
FileFilter filterForImageFolders = new FileFilter() { public boolean accept(File folder) { try { //Checking only directories, since we are checking for files within //a directory if(folder.isDirectory()) { File[] listOfFiles = folder.listFiles(); if (listOfFiles == null) return false; //For each file in the directory... for (File file : listOfFiles) { //Check if the extension is one of the supported filetypes //imageExtensions is a String[] containing image filetypes (eg "png") for (String ext : imageExtensions) { if (file.getName().endsWith("." + ext)) return true; } } } return false; } catch (SecurityException e) { Log.v("debug", "Access Denied"); return false; } } };
Then change the first example to:
File[] directories = file.listFiles(filterForImageFolders);
This should only return directories containing images. Hope this helps some!
source share