Explorar el Código

sometimes getExternalFilesDir returns null, and the app crashes in this case

Nicolas Van Eenaeme hace 6 años
padre
commit
4c4c5eab7d
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. 5
    1
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 5
- 1
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Ver fichero

@@ -213,7 +213,11 @@ public class RNFetchBlobFS {
213 213
         state = Environment.getExternalStorageState();
214 214
         if (state.equals(Environment.MEDIA_MOUNTED)) {
215 215
             res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
216
-            res.put("SDCardApplicationDir", ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath());
216
+
217
+            File externalDirectory = ctx.getExternalFilesDir(null);
218
+            if (externalDirectory != null) {
219
+                res.put("SDCardApplicationDir", externalDirectory.getParentFile().getAbsolutePath());
220
+            }
217 221
         }
218 222
         res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
219 223
         return res;