瀏覽代碼

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

Nicolas Van Eenaeme 6 年之前
父節點
當前提交
4c4c5eab7d
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5
    1
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 5
- 1
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 查看文件

@@ -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;