判断SD卡剩余空间是否可用

来源:互联网 发布:机房网络验收 编辑:程序博客网 时间:2024/06/12 01:04
 
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;}

原创粉丝点击