Browse Source

Added MainBundleDir to Android #138

Ben Hsieh 8 years ago
parent
commit
3e57fd5b9c
2 changed files with 5 additions and 14 deletions
  1. 3
    13
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
  2. 2
    1
      src/fs.js

+ 3
- 13
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

189
     static public Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
189
     static public Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
190
         Map<String, Object> res = new HashMap<>();
190
         Map<String, Object> res = new HashMap<>();
191
 
191
 
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
-        }
203
         res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
192
         res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
204
         res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
193
         res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
205
         res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
194
         res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
208
         res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
197
         res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
209
         res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
198
         res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
210
         res.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
199
         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);
212
         return res;
202
         return res;
213
     }
203
     }
214
 
204
 
703
             }
693
             }
704
             else {
694
             else {
705
                 if (!created) {
695
                 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.");
707
                     return;
697
                     return;
708
                 }
698
                 }
709
                 OutputStream ostream = new FileOutputStream(dest);
699
                 OutputStream ostream = new FileOutputStream(dest);

+ 2
- 1
src/fs.js View File

29
     MovieDir : RNFetchBlob.MovieDir,
29
     MovieDir : RNFetchBlob.MovieDir,
30
     DownloadDir : RNFetchBlob.DownloadDir,
30
     DownloadDir : RNFetchBlob.DownloadDir,
31
     DCIMDir : RNFetchBlob.DCIMDir,
31
     DCIMDir : RNFetchBlob.DCIMDir,
32
-    SDCardDir : RNFetchBlob.SDCardDir
32
+    SDCardDir : RNFetchBlob.SDCardDir,
33
+    MainBundleDir : RNFetchBlob.MainBundleDir
33
 }
34
 }
34
 
35
 
35
 /**
36
 /**