Browse Source

Add #162 Android implementation

Ben Hsieh 7 years ago
parent
commit
9b792d1467

+ 11
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java View File

257
         RNFetchBlobReq.progressReport.put(taskId, config);
257
         RNFetchBlobReq.progressReport.put(taskId, config);
258
     }
258
     }
259
 
259
 
260
+    @ReactMethod
261
+    public void df(final Callback callback) {
262
+        fsThreadPool.execute(new Runnable() {
263
+            @Override
264
+            public void run() {
265
+                RNFetchBlobFS.df(callback);
266
+            }
267
+        });
268
+    }
269
+
270
+
260
     @ReactMethod
271
     @ReactMethod
261
     public void enableUploadProgressReport(String taskId, int interval, int count) {
272
     public void enableUploadProgressReport(String taskId, int interval, int count) {
262
         RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig(true, interval, count, RNFetchBlobProgressConfig.ReportType.Upload);
273
         RNFetchBlobProgressConfig config = new RNFetchBlobProgressConfig(true, interval, count, RNFetchBlobProgressConfig.ReportType.Upload);

+ 16
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

6
 import android.media.MediaScannerConnection;
6
 import android.media.MediaScannerConnection;
7
 import android.net.Uri;
7
 import android.net.Uri;
8
 import android.os.AsyncTask;
8
 import android.os.AsyncTask;
9
+import android.os.Build;
9
 import android.os.Environment;
10
 import android.os.Environment;
11
+import android.os.StatFs;
10
 import android.os.SystemClock;
12
 import android.os.SystemClock;
11
 import android.util.Base64;
13
 import android.util.Base64;
12
 
14
 
744
         }
746
         }
745
     }
747
     }
746
 
748
 
749
+    static void df(Callback callback) {
750
+        StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
751
+        WritableMap args = Arguments.createMap();
752
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
753
+            args.putString("internal_free", String.valueOf(stat.getFreeBytes()));
754
+            args.putString("internal_total", String.valueOf(stat.getTotalBytes()));
755
+            StatFs statEx = new StatFs(Environment.getExternalStorageDirectory().getPath());
756
+            args.putString("external_free", String.valueOf(statEx.getFreeBytes()));
757
+            args.putString("external_total", String.valueOf(statEx.getTotalBytes()));
758
+
759
+        }
760
+        callback.invoke(null ,args);
761
+    }
762
+
747
     /**
763
     /**
748
      * Remove files in session.
764
      * Remove files in session.
749
      * @param paths An array of file paths.
765
      * @param paths An array of file paths.