use of android.os.StatFs in project AndroidUtilCode by Blankj.
the class SDCardUtils method getSDCardInfo.
/**
* 获取SD卡信息
*
* @return SDCardInfo
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getSDCardInfo() {
if (!isSDCardEnable())
return null;
SDCardInfo sd = new SDCardInfo();
sd.isExist = true;
StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
sd.totalBlocks = sf.getBlockCountLong();
sd.blockByteSize = sf.getBlockSizeLong();
sd.availableBlocks = sf.getAvailableBlocksLong();
sd.availableBytes = sf.getAvailableBytes();
sd.freeBlocks = sf.getFreeBlocksLong();
sd.freeBytes = sf.getFreeBytes();
sd.totalBytes = sf.getTotalBytes();
return sd.toString();
}
use of android.os.StatFs in project orWall by EthACKdotOrg.
the class Toolbox method hasEnoughSpaceOnPartition.
/**
* Check if there is enough space on partition where target is located
*
* @param size
* size of file to put on partition
* @param target
* path where to put the file
*
* @return true if it will fit on partition of target, false if it will not fit.
*/
public boolean hasEnoughSpaceOnPartition(String target, long size) {
try {
// new File(target).getFreeSpace() (API 9) is not working on data partition
// get directory without file
String directory = new File(target).getParent().toString();
StatFs stat = new StatFs(directory);
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
long availableSpace = availableBlocks * blockSize;
Log.i(RootCommands.TAG, "Checking for enough space: Target: " + target + ", directory: " + directory + " size: " + size + ", availableSpace: " + availableSpace);
if (size < availableSpace) {
return true;
} else {
Log.e(RootCommands.TAG, "Not enough space on partition!");
return false;
}
} catch (Exception e) {
// if new StatFs(directory) fails catch IllegalArgumentException and just return true as
// workaround
Log.e(RootCommands.TAG, "Problem while getting available space on partition!", e);
return true;
}
}
use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getSDcardTotalSize.
/**
* 获取手机SD卡总空间
*/
private static long getSDcardTotalSize() {
if (checkSdCard()) {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long blockCountLong = mStatFs.getBlockCountLong();
return blockSizeLong * blockCountLong;
} else {
return 0;
}
}
use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getSDcardAvailableSize.
/**
* 获取SDka可用空间
*/
private static long getSDcardAvailableSize() {
if (checkSdCard()) {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long availableBlocksLong = mStatFs.getAvailableBlocksLong();
return blockSizeLong * availableBlocksLong;
} else {
return 0;
}
}
use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getPhoneTotalSize.
/**
* 获取手机内部存储总空间
*/
public static long getPhoneTotalSize() {
if (!checkSdCard()) {
File path = Environment.getDataDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long blockCountLong = mStatFs.getBlockCountLong();
return blockSizeLong * blockCountLong;
} else {
return getSDcardTotalSize();
}
}
Aggregations