Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 3e57fd5

Browse files
committed
Added MainBundleDir to Android #138
1 parent 3d27ac0 commit 3e57fd5

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,6 @@ static public void readFile(String path, String encoding, final Promise promise
189189
static public Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
190190
Map<String, Object> res = new HashMap<>();
191191

192-
PackageManager m = ctx.getPackageManager();
193-
String s = ctx.getPackageName();
194-
PackageInfo p = null;
195-
196-
try {
197-
p = m.getPackageInfo(s, 0);
198-
s = p.applicationInfo.dataDir;
199-
res.put("MainBundleDir", s);
200-
} catch (PackageManager.NameNotFoundException e) {
201-
e.printStackTrace();
202-
}
203192
res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
204193
res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
205194
res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
@@ -208,7 +197,8 @@ static public Map<String, Object> getSystemfolders(ReactApplicationContext ctx)
208197
res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
209198
res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
210199
res.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
211-
res.put("SDCard", Environment.getExternalStorageDirectory().getAbsolutePath());
200+
// res.put("SDCard", Environment.getExternalStorageDirectory().getAbsolutePath());
201+
res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
212202
return res;
213203
}
214204

@@ -703,7 +693,7 @@ static void createFile(String path, String data, String encoding, Callback callb
703693
}
704694
else {
705695
if (!created) {
706-
callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists");
696+
callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists, or the file already exists. If you intended to overwrite the existing file use fs.writeFile instead.");
707697
return;
708698
}
709699
OutputStream ostream = new FileOutputStream(dest);

src/fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const dirs = {
2929
MovieDir : RNFetchBlob.MovieDir,
3030
DownloadDir : RNFetchBlob.DownloadDir,
3131
DCIMDir : RNFetchBlob.DCIMDir,
32-
SDCardDir : RNFetchBlob.SDCardDir
32+
SDCardDir : RNFetchBlob.SDCardDir,
33+
MainBundleDir : RNFetchBlob.MainBundleDir
3334
}
3435

3536
/**

0 commit comments

Comments
 (0)