mirror of
https://github.com/status-im/react-native-fs.git
synced 2026-08-30 19:41:12 +00:00
new getFSInfo command
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.StatFs;
|
||||
import android.util.Base64;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -300,6 +301,26 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
||||
// TODO: Not sure what equilivent would be?
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getFSInfo(Callback callback) {
|
||||
File path = Environment.getDataDirectory();
|
||||
StatFs stat = new StatFs(path.getPath());
|
||||
long totalSpace;
|
||||
long freeSpace;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 18) {
|
||||
totalSpace = stat.getTotalBytes();
|
||||
freeSpace = stat.getFreeBytes();
|
||||
} else {
|
||||
long blockSize = stat.getBlockSize();
|
||||
totalSpace = blockSize * stat.getBlockCount();
|
||||
freeSpace = blockSize * stat.getAvailableBlocks();
|
||||
}
|
||||
HashMap info = new HashMap();
|
||||
info.put("totalSpace", totalSpace);
|
||||
info.put("freeSpace", freeSpace);
|
||||
callback.invoke(null, info);
|
||||
}
|
||||
|
||||
private WritableMap makeErrorPayload(Exception ex) {
|
||||
WritableMap error = Arguments.createMap();
|
||||
error.putString("message", ex.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user