new getFSInfo command

This commit is contained in:
Kyle Corbitt
2016-05-03 21:25:33 +01:00
committed by Chris Dell
parent 2196577b66
commit 33d637e42e
4 changed files with 62 additions and 2 deletions
@@ -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());