本文整理匯總了Java中android.os.StatFs.getFreeBlocks方法的典型用法代碼示例。如果您正苦於以下問題:Java StatFs.getFreeBlocks方法的具體用法?Java StatFs.getFreeBlocks怎麽用?Java StatFs.getFreeBlocks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.StatFs
的用法示例。
在下文中一共展示了StatFs.getFreeBlocks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFreeStorageSpace
import android.os.StatFs; //導入方法依賴的package包/類
/**
* Gets the information about the free storage space, including reserved blocks,
* either internal or external depends on the given input
* @param storageType Internal or external storage type
* @return available space in bytes, -1 if no information is available
*/
@SuppressLint("DeprecatedMethod")
public long getFreeStorageSpace(StorageType storageType) {
ensureInitialized();
maybeUpdateStats();
StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs;
if (statFS != null) {
long blockSize, availableBlocks;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = statFS.getBlockSizeLong();
availableBlocks = statFS.getFreeBlocksLong();
} else {
blockSize = statFS.getBlockSize();
availableBlocks = statFS.getFreeBlocks();
}
return blockSize * availableBlocks;
}
return -1;
}
示例2: getSDCardFreeSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取SD卡空閑空間大小(有多少空間還沒被占用)
*
* @return
*/
public static long getSDCardFreeSize() {
long freeBlockCount;
long blockSize;
if (isSDCardMounted()) {
String dir = getSDCardBaseDir();
//StatFs是從C語言引過來的
StatFs statFs = new StatFs(dir);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
freeBlockCount = statFs.getFreeBlocksLong();//有多少塊
blockSize = statFs.getBlockSizeLong();//每塊有多大
} else {
freeBlockCount = statFs.getFreeBlocks();//有多少塊
blockSize = statFs.getBlockSize();//每塊有多大
}
return freeBlockCount * blockSize / 1024 / 1024; //總大小
}
return 0;
}
示例3: getFreeSpaceSize
import android.os.StatFs; //導入方法依賴的package包/類
public static Long getFreeSpaceSize(StatFs statFs) {
long freeSpaceSize = 0;
try {
if (VERSION.SDK_INT >= 18) {
freeSpaceSize = statFs.getFreeBlocksLong() * statFs.getBlockSizeLong();
} else {
freeSpaceSize = ((long) statFs.getFreeBlocks()) * ((long) statFs.getBlockSize());
}
} catch (Throwable e) {
LOG.w(TAG, "getScreenHeightWidth failed(Throwable): " + e.getMessage());
}
return Long.valueOf(freeSpaceSize);
}