From beee401baad76d354a25f053f237e99d3915be64 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sun, 20 Jan 2019 11:42:01 +0000 Subject: [PATCH] Fix crash after sdcard was ejected (fixes #249) (#250) --- .../syncthingandroid/activities/FolderPickerActivity.java | 1 + .../syncthingandroid/activities/TipsAndTricksActivity.java | 1 + .../main/java/com/nutomic/syncthingandroid/util/FileUtils.java | 1 + 3 files changed, 3 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java index 3a7530ec..31c2ca78 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java @@ -108,6 +108,7 @@ public class FolderPickerActivity extends SyncthingActivity if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { roots.addAll(Arrays.asList(getExternalFilesDirs(null))); roots.remove(getExternalFilesDir(null)); + roots.remove(null); // getExternalFilesDirs may return null for an ejected SDcard. } String rootDir = getIntent().getStringExtra(EXTRA_ROOT_DIRECTORY); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/TipsAndTricksActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/TipsAndTricksActivity.java index b9157715..22dd8314 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/TipsAndTricksActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/TipsAndTricksActivity.java @@ -48,6 +48,7 @@ public class TipsAndTricksActivity extends SyncthingActivity { ArrayList externalFilesDir = new ArrayList<>(); externalFilesDir.addAll(Arrays.asList(getExternalFilesDirs(null))); externalFilesDir.remove(getExternalFilesDir(null)); + externalFilesDir.remove(null); // getExternalFilesDirs may return null for an ejected SDcard. if (externalFilesDir.size() > 0) { String absExternalStorageAppFilesPath = externalFilesDir.get(0).getAbsolutePath(); mTipListAdapter.add(getString(R.string.tip_write_to_sdcard_title), diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java index 88713b56..63f68b3e 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java @@ -167,6 +167,7 @@ public class FileUtils { ArrayList externalFilesDir = new ArrayList<>(); externalFilesDir.addAll(Arrays.asList(context.getExternalFilesDirs(null))); externalFilesDir.remove(context.getExternalFilesDir(null)); + externalFilesDir.remove(null); // getExternalFilesDirs may return null for an ejected SDcard. if (externalFilesDir.size() == 0) { Log.w(TAG, "Could not determine app's private files directory on external storage."); return null;