Skip to content

Commit d2c4d16

Browse files
author
Ron Radtke
committed
Covering the last two dirs in methods to prevent crashing the app in case it's null
Fixes #34
1 parent fb7ed4f commit d2c4d16

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ else if(resolved == null) {
250250
static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
251251
Map<String, Object> res = new HashMap<>();
252252

253-
res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
254-
res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
253+
res.put("DocumentDir", getFilesDirPath(ctx));
254+
res.put("CacheDir", getCacheDirPath(ctx));
255255
res.put("DCIMDir", getExternalFilesDirPath(ctx, Environment.DIRECTORY_DCIM));
256256
res.put("PictureDir", getExternalFilesDirPath(ctx, Environment.DIRECTORY_PICTURES));
257257
res.put("MusicDir", getExternalFilesDirPath(ctx, Environment.DIRECTORY_MUSIC));
@@ -282,6 +282,18 @@ static String getExternalFilesDirPath(ReactApplicationContext ctx, String type)
282282
return "";
283283
}
284284

285+
static String getFilesDirPath(ReactApplicationContext ctx) {
286+
File dir = ctx.getFilesDir();
287+
if (dir != null) return dir.getAbsolutePath();
288+
return "";
289+
}
290+
291+
static String getCacheDirPath(ReactApplicationContext ctx) {
292+
File dir = ctx.getCacheDir();
293+
if (dir != null) return dir.getAbsolutePath();
294+
return "";
295+
}
296+
285297
static public void getSDCardDir(ReactApplicationContext ctx, Promise promise) {
286298
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
287299
try {

0 commit comments

Comments
 (0)