From: Keith Packard Date: Sun, 10 Oct 2021 03:58:26 +0000 (-0700) Subject: altosdroid: Switch storage to media dir X-Git-Tag: 1.9.10~1^2~5 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=4b3ccb73a26f91917d327558295506ce3c02d684 altosdroid: Switch storage to media dir Even with the WRITE_EXTERNAL_STORAGE permission, we appear to no longer have permission to write to a random external storage dir. Instead, we only have permission to write to an app-specific dir, buried deep in the directory tree. We can get that directory name with getExternalMediaDirs()[0]. Signed-off-by: Keith Packard --- diff --git a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java index 5d836f5d..170353ab 100644 --- a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java +++ b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java @@ -78,15 +78,18 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend { public String getString(String key, String def) { String ret; - ret = prefs.getString(key, def); -// AltosDebug.debug("AltosDroidPreferencesBackend get string %s:\n", key); -// if (ret == null) -// AltosDebug.debug(" (null)\n"); -// else { -// String[] lines = ret.split("\n"); -// for (String l : lines) -// AltosDebug.debug(" %s\n", l); -// } + if (key.equals(AltosPreferences.logdirPreference)) + ret = null; + else + ret = prefs.getString(key, def); + AltosDebug.debug("AltosDroidPreferencesBackend get string %s:\n", key); + if (ret == null) + AltosDebug.debug(" (null)\n"); + else { + String[] lines = ret.split("\n"); + for (String l : lines) + AltosDebug.debug(" %s\n", l); + } return ret; } @@ -135,7 +138,7 @@ public class AltosDroidPreferencesBackend extends AltosPreferencesBackend { } public File homeDirectory() { - return Environment.getExternalStorageDirectory(); + return context.getExternalMediaDirs()[0]; } public void debug(String format, Object ... arguments) {