So I am aware that there is SD Card access API which allows us to write files via DocumentProvider and DocumentFiles. I have made it work on removable SD Cards. I was always confused about External and Internal Storage. I always thought External Storage is Always SD card but today I came to know that it is not so.
So I have three question .
Question1 , how to know if Files are stored in external emulated storage or sdcard ? One solution maybe by searching for instances of "sdcard0" or "emulated" in the file path. Will this solution always work? I mean on all phones?
Question 2 what to Use for writing files on emulated storage(non removable external storage) normal files or DocumentFile?
Question 3 If solution of Q2 is Document File then why doesn't this work ?
private static String[] getExtSdCardPaths() { List paths = new ArrayList<>();
for (File file : GlobalSongList.GetInstance().getApplicationContext().getExternalFilesDirs("external")) {
if (file != null && !file.equals(GlobalSongList.GetInstance().getApplicationContext().getExternalFilesDir("external"))) {
int index = file.getAbsolutePath().lastIndexOf("/Android/data");
if (index < 0) {
Log.w("StorageAccessAPI", "Unexpected external file dir: " + file.getAbsolutePath());
}
else {
String path = file.getAbsolutePath().substring(0, index);
try {
path = new File(path).getCanonicalPath();
}
catch (IOException e) {
// Keep non-canonical path.
}
paths.add(path);
}
}
}
return paths.toArray(new String[paths.size()]);
}