Kaynağa Gözat

#2 refactor android code

Ben Hsieh 8 yıl önce
ebeveyn
işleme
d077c7e682

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Dosyayı Görüntüle

@@ -37,7 +37,7 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
37 37
     @ReactMethod
38 38
     public void flush(String taskId) {
39 39
         try {
40
-            new File(RNFetchBlobFS.TempFilePath + taskId).delete();
40
+            new File(RNFetchBlobFS.getTmpPath(this.getReactApplicationContext(), taskId)).delete();
41 41
         } catch(Exception err) {
42 42
             WritableMap args = Arguments.createMap();
43 43
             args.putString("event", "error");

+ 5
- 4
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Dosyayı Görüntüle

@@ -17,12 +17,13 @@ import cz.msebera.android.httpclient.util.EncodingUtils;
17 17
  */
18 18
 public class RNFetchBlobFS {
19 19
 
20
-    static String DocumentDir = Environment.getExternalStorageDirectory().toString();
21
-    static String TempFilePath = Environment.getExternalStorageDirectory().toString() + "/RNFetchBlobCache/dltmp";
22
-
23 20
     ReactApplicationContext mCtx;
24 21
     DeviceEventManagerModule.RCTDeviceEventEmitter emitter;
25 22
 
23
+    static public String getTmpPath(ReactApplicationContext ctx, String taskId) {
24
+        return ctx.getFilesDir() + "/RNFetchBlobTmp_" + taskId;
25
+    }
26
+
26 27
 
27 28
     RNFetchBlobFS(ReactApplicationContext ctx) {
28 29
         this.mCtx = ctx;
@@ -32,7 +33,7 @@ public class RNFetchBlobFS {
32 33
     public void readStream(String taskId, String encoding) {
33 34
         try {
34 35
 
35
-            FileInputStream fs = mCtx.openFileInput(RNFetchBlobFS.TempFilePath + taskId);
36
+            FileInputStream fs = mCtx.openFileInput(mCtx.getFilesDir() + "/fetchblobtmp_"+ taskId);
36 37
             byte[] buffer = new byte[1024];
37 38
             int cursor = 0;
38 39
             boolean error = false;

+ 4
- 3
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFileHandler.java Dosyayı Görüntüle

@@ -2,6 +2,7 @@ package com.RNFetchBlob;
2 2
 
3 3
 import com.facebook.react.bridge.Arguments;
4 4
 import com.facebook.react.bridge.Callback;
5
+import com.facebook.react.bridge.ReactApplicationContext;
5 6
 import com.facebook.react.bridge.ReactContext;
6 7
 import com.facebook.react.bridge.WritableMap;
7 8
 import com.facebook.react.modules.core.DeviceEventManagerModule;
@@ -20,9 +21,9 @@ public class RNFetchBlobFileHandler extends FileAsyncHttpResponseHandler {
20 21
     ReactContext mCtx;
21 22
     String mTaskId;
22 23
 
23
-    RNFetchBlobFileHandler(ReactContext ctx, String taskId, Callback onResponse) {
24
-        // save temp file to RNFetchBlobCache/dltmp${taskId}
25
-        super(new File(RNFetchBlobFS.TempFilePath + taskId), false, false);
24
+    RNFetchBlobFileHandler(ReactApplicationContext ctx, String taskId, Callback onResponse) {
25
+        // save temp file to application storage
26
+        super(new File(RNFetchBlobFS.getTmpPath(ctx, taskId)), false, false);
26 27
         this.onResponse = onResponse;
27 28
         this.mTaskId = taskId;
28 29
         this.mCtx = ctx;