-
-
Save AbreuY/a90cee777912958ccc9e0096ae3d05a9 to your computer and use it in GitHub Desktop.
Load Android SDCard Folder for different devices (Android Standard, Samsung Galaxy S, HTC Incredible)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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