use of android.os.StatFs in project android-common by litesuits.
the class SdCardUtil method getSDCardInfo.
/**
* Get SD card info detail.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static SDCardInfo getSDCardInfo() {
SDCardInfo sd = new SDCardInfo();
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
sd.isExist = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
File sdcardDir = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(sdcardDir.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();
}
}
if (Log.isPrint) {
Log.i(TAG, sd.toString());
}
return sd;
}
use of android.os.StatFs in project RxSample by Aload.
the class Utils method checkRomSpaceEnough.
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
long allSize;
long availableSize = 0;
try {
File data = Environment.getDataDirectory();
StatFs sf = new StatFs(data.getPath());
availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
} catch (Exception e) {
allSize = 0;
}
return allSize != 0 && availableSize > limitSize;
}
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 AndroidUtilCode by Blankj.
the class SDCardUtils method getFreeSpace.
/**
* 获取SD卡剩余空间
*
* @return SD卡剩余空间
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getFreeSpace() {
if (!isSDCardEnable())
return null;
StatFs stat = new StatFs(getSDCardPath());
long blockSize, availableBlocks;
availableBlocks = stat.getAvailableBlocksLong();
blockSize = stat.getBlockSizeLong();
return ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize);
}
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();
}
Aggregations