public class Explorer {
String TAG = "Explorer";
private final String DISK_DIR = "/mnt";
public static final int DIR_SDCARD = 0;
public static final int DIR_SDCARD_EX = 1; // external sdcard
public static final int DIR_USB = 2; // usb external storage
private static List<String> pathList = new ArrayList<String>();
public String getDiskPath(int typeDir) {
File[] files = new File(DISK_DIR).listFiles();
String filePath;
for (int i = 0; i < files.length; i++) {
filePath = files[i].getAbsolutePath().toLowerCase();
Log.d(TAG, "getDiskPath " + filePath);
switch (typeDir) {
case DIR_SDCARD:
if(filePath.equals("/mnt/sdcard"))
return filePath;
break;
case DIR_SDCARD_EX:
if (filePath.contains("sdcard") && filePath.contains("ext")) {
return filePath;
}
break;
case DIR_USB:
if(filePath.contains("usb"))
return filePath;
break;
}
}
return null;
}
private void loadFileList(String dir, final String fileType) {
File fileDir = new File(dir);
if (fileDir.exists()) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String filename) {
File sel = new File(dir, filename);
return filename.endsWith(fileType) || sel.isDirectory();
}
};
File[] files = fileDir.listFiles(filter);
if(files!=null){
for (File file : files) {
String absolutePath = file.getAbsolutePath();
if(file.isDirectory()){
loadFileList(absolutePath, fileType);
}else {
pathList.add(absolutePath);
}
}
}
}
}
public List<String> getFileList(String dir, final String fileType){
loadFileList(dir, fileType);
return pathList;
}
}