网上搜了用安卓的原生写法,react-native通过navtiveModules的方式来获取,但是那个方法报long的错误,好像不对,用不了
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;
public class CacheManagerModule extends ReactContextBaseJavaModule {
CacheManagerModule(ReactApplicationContext context) {
super(context);
}
@Override
public String getName() {
return "CacheManager";
}
@ReactMethod
public void getAppCacheSize(Promise promise) {
long size = getFolderSize(context.getCacheDir());
promise.resolve(size);
}
private long getFolderSize(File file) {
long size = 0;
try {
File[] fileList = file.listFiles();
for (File aFileList : fileList) {
if (aFileList.isDirectory()) {
size = size + getFolderSize(aFileList);
} else {
size = size + aFileList.length();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return size;
}
}
能给个安卓和IOS 获取缓存和清除缓存的正确写法么
或者说 APP的缓存,就是Storage那些么?