Skip to content

Instantly share code, notes, and snippets.

@christoph-jerolimov
Created January 10, 2011 11:33
Show Gist options
  • Save christoph-jerolimov/772667 to your computer and use it in GitHub Desktop.
Save christoph-jerolimov/772667 to your computer and use it in GitHub Desktop.
Load Android SDCard Folder for different devices (Android Standard, Samsung Galaxy S, HTC Incredible)
private String getSdcardFolder() {
File externalStorage = Environment.getExternalStorageDirectory();
if (externalStorage.exists() && externalStorage.canWrite()) {
File trySubDir1 = new File(externalStorage, "external_sd");
File trySubDir2 = new File(externalStorage, "sd");
if (trySubDir1.exists() && trySubDir1.canWrite()) {
return trySubDir1.getAbsolutePath();
} else if (trySubDir2.exists() && trySubDir2.canWrite()) {
return trySubDir2.getAbsolutePath();
} else {
return externalStorage.getAbsolutePath();
}
}
String[] tryOtherSubDirs = new String[] {
"/sdcard/external_sd",
"/sdcard/sd",
"/mnt/sdcard/external_sd",
"/mnt/sdcard/sd",
"/mnt/sdcard"
};
for (String trySubDir : tryOtherSubDirs) {
File dir = new File(trySubDir);
if (dir.exists() && dir.canWrite()) {
return dir.getAbsolutePath();
}
}
return "/sdcard";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment