altosdroid: Switch storage to media dir
authorKeith Packard <keithp@keithp.com>
Sun, 10 Oct 2021 03:58:26 +0000 (20:58 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 10 Oct 2021 03:58:26 +0000 (20:58 -0700)
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 <keithp@keithp.com>
altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroidPreferencesBackend.java

index 5d836f5dceeb7f21f9711b0c77beffadfe5fadbc..170353ab4838098035f6e1dc37768bb0ee41f9f4 100644 (file)
@@ -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) {