From 4b3ccb73a26f91917d327558295506ce3c02d684 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 9 Oct 2021 20:58:26 -0700 Subject: [PATCH] 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 --- .../AltosDroidPreferencesBackend.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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) { -- 2.30.2