private static final long LOW_STORAGE_THRESHOLD = 1024 * 1024 * 10;
public static long getAvailableStorage() {
String storageDirectory = null;
storageDirectory = Environment.getExternalStorageDirectory().toString();
Log.d(TAG, "getAvailableStorage. storageDirectory : " + storageDirectory);
try {
StatFs stat = new StatFs(storageDirectory);
avaliableSize = ((long) stat.getAvailableBlocks() * (long) stat.getBlockSize());
Log.d(TAG, "getAvailableStorage. avaliableSize : " + avaliableSize);
return avaliableSize;
} catch (RuntimeException ex) {
// if we can't stat the filesystem then we don't know how many
// free bytes exist. It might be zero but just leave it
// blank since we really don't know.
Log.e(TAG, "getAvailableStorage - exception. return 0");
return 0;
}
}
public static boolean checkAvailableStorage() {
Log.d(TAG,"checkAvailableStorage E");
if(getAvailableStorage() < LOW_STORAGE_THRESHOLD) {
return false;
}
return true;
}
判断SD卡剩余空间是否可用
最新推荐文章于 2018-06-11 16:08:39 发布