Created
September 7, 2017 20:35
-
-
Save kwong93/eed0244c0d2202aa7adfdd05fef14735 to your computer and use it in GitHub Desktop.
Android how to get all external directory files including sd card
This file contains 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
public List<File> getExternalDirectoryRoots(Context context) { | |
File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null); | |
List<File> externalDirectories = new ArrayList<>(); | |
Set<String> stringSet = new HashSet<>(); | |
for (File file : externalFilesDirs) { | |
String[] split = file.getAbsolutePath().split("/"); | |
if (split.length > 1) { | |
stringSet.add(split[1]); | |
} | |
} | |
for (String str : stringSet) { | |
externalDirectories.add(new File(str)); | |
} | |
return externalDirectories; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment