From 4c4c5eab7dfec84d748e814e19fe69e2f468efa3 Mon Sep 17 00:00:00 2001 From: Nicolas Van Eenaeme Date: Mon, 4 Jun 2018 13:44:24 +0200 Subject: [PATCH] sometimes getExternalFilesDir returns null, and the app crashes in this case --- android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java index 7a7910546..7e29fcce2 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java @@ -213,7 +213,11 @@ static public Map getSystemfolders(ReactApplicationContext ctx) state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath()); - res.put("SDCardApplicationDir", ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath()); + + File externalDirectory = ctx.getExternalFilesDir(null); + if (externalDirectory != null) { + res.put("SDCardApplicationDir", externalDirectory.getParentFile().getAbsolutePath()); + } } res.put("MainBundleDir", ctx.getApplicationInfo().dataDir); return res;