ソースを参照

Added MainBundleDir to Android #138

Ben Hsieh 7 年 前
コミット
3e57fd5b9c
共有2 個のファイルを変更した5 個の追加14 個の削除を含む
  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 ファイルの表示

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

+ 2
- 1
src/fs.js ファイルの表示

@@ -29,7 +29,8 @@ const dirs = {
29 29
     MovieDir : RNFetchBlob.MovieDir,
30 30
     DownloadDir : RNFetchBlob.DownloadDir,
31 31
     DCIMDir : RNFetchBlob.DCIMDir,
32
-    SDCardDir : RNFetchBlob.SDCardDir
32
+    SDCardDir : RNFetchBlob.SDCardDir,
33
+    MainBundleDir : RNFetchBlob.MainBundleDir
33 34
 }
34 35
 
35 36
 /**