本文整理匯總了Java中android.os.StatFs.getBlockCountLong方法的典型用法代碼示例。如果您正苦於以下問題:Java StatFs.getBlockCountLong方法的具體用法?Java StatFs.getBlockCountLong怎麽用?Java StatFs.getBlockCountLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.StatFs
的用法示例。
在下文中一共展示了StatFs.getBlockCountLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSDcardTotalSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取手機SD卡總空間
*
* @return
*/
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;
}
}
示例2: calculateDiskCacheSize
import android.os.StatFs; //導入方法依賴的package包/類
@TargetApi(JELLY_BEAN_MR2)
static long calculateDiskCacheSize(File dir) {
long size = MIN_DISK_CACHE_SIZE;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
//noinspection deprecation
long blockCount =
SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockCount() : statFs.getBlockCountLong();
//noinspection deprecation
long blockSize =
SDK_INT < JELLY_BEAN_MR2 ? (long) statFs.getBlockSize() : statFs.getBlockSizeLong();
long available = blockCount * blockSize;
// Target 2% of the total space.
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
// Bound inside min/max size for disk cache.
return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
}
示例3: getTotalStorageSpace
import android.os.StatFs; //導入方法依賴的package包/類
/**
* Gets the information about the total storage space,
* 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 getTotalStorageSpace(StorageType storageType) {
ensureInitialized();
maybeUpdateStats();
StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs;
if (statFS != null) {
long blockSize, totalBlocks;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = statFS.getBlockSizeLong();
totalBlocks = statFS.getBlockCountLong();
} else {
blockSize = statFS.getBlockSize();
totalBlocks = statFS.getBlockCount();
}
return blockSize * totalBlocks;
}
return -1;
}
示例4: getSDCardInfo
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取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();
}
示例5: getSDCardSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取SD卡全部內存空間大小
*
* @return
*/
public static long getSDCardSize() {
long blockCount;
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) {
blockCount = statFs.getBlockCountLong();//有多少塊
blockSize = statFs.getBlockSizeLong();//每塊有多大
} else {
blockCount = statFs.getBlockCount();//有多少塊
blockSize = statFs.getBlockSize();//每塊有多大
}
return blockCount * blockSize / 1024 / 1024; //總大小
}
return 0;
}
示例6: getSDCardInfo
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取SD卡信息
*
* @return SDCardInfo
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getSDCardInfo() {
SDCardInfo sd = new SDCardInfo();
if (!isSDCardEnable()) return "sdcard unable!";
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();
}
示例7: calculateDiskCacheSize
import android.os.StatFs; //導入方法依賴的package包/類
private static long calculateDiskCacheSize(File dir) {
long size = MIN_DISK_CACHE_SIZE;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long available;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
available = statFs.getBlockCountLong() * statFs.getBlockSizeLong();
} else {
// checked at runtime
//noinspection deprecation
available = statFs.getBlockCount() * statFs.getBlockSize();
}
// Target 2% of the total space.
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
// Bound inside min/max size for disk cache.
return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
}
示例8: getUsedSpace
import android.os.StatFs; //導入方法依賴的package包/類
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public long getUsedSpace(SizeUnit sizeUnit) {
String path = buildAbsolutePath();
StatFs statFs = new StatFs(path);
long availableBlocks;
long blockSize;
long totalBlocks;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
availableBlocks = statFs.getAvailableBlocks();
blockSize = statFs.getBlockSize();
totalBlocks = statFs.getBlockCount();
} else {
availableBlocks = statFs.getAvailableBlocksLong();
blockSize = statFs.getBlockSizeLong();
totalBlocks = statFs.getBlockCountLong();
}
long usedBytes = totalBlocks * blockSize - availableBlocks * blockSize;
return usedBytes / sizeUnit.inBytes();
}
示例9: getFreeSpace
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲得可用存儲空間
*
* @return 可用存儲空間(單位b)
*/
public long getFreeSpace() {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize;//區塊的大小
long totalBlocks;//區塊總數
long availableBlocks;//可用區塊的數量
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSizeLong();
totalBlocks = stat.getBlockCountLong();
availableBlocks = stat.getAvailableBlocksLong();
} else {
blockSize = stat.getBlockSize();
totalBlocks = stat.getBlockCount();
availableBlocks = stat.getAvailableBlocks();
}
Log.e(TAG, "totalSpace:" + blockSize * totalBlocks + "...availableSpace:" + blockSize * availableBlocks);
return blockSize * availableBlocks;
}
示例10: getPhoneTotalSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取手機內部存儲總空間
*
* @return
*/
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();
}
示例11: getSDCardInfo
import android.os.StatFs; //導入方法依賴的package包/類
@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();
}
示例12: calculateDiskCacheSize
import android.os.StatFs; //導入方法依賴的package包/類
private static long calculateDiskCacheSize(File dir) {
long size = 5242880L;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long blockCount = Build.VERSION.SDK_INT < 18 ? (long) statFs.getBlockCount() : statFs.getBlockCountLong();
long blockSize = Build.VERSION.SDK_INT < 18 ? (long) statFs.getBlockSize() : statFs.getBlockSizeLong();
long available = blockCount * blockSize;
size = available / 50L;
} catch (IllegalArgumentException ignored) {
}
return Math.max(Math.min(size, 52428800L), 5242880L);
}
示例13: getSDcardTotalSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取手機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;
}
}
示例14: getPhoneTotalSize
import android.os.StatFs; //導入方法依賴的package包/類
/**
* 獲取手機內部存儲總空間
*/
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();
}
}
示例15: getBlockCount
import android.os.StatFs; //導入方法依賴的package包/類
/**
* See {@link android.os.StatFs#getBlockCount()}.
*/
@SuppressWarnings("deprecation")
public static long getBlockCount(StatFs statFs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return statFs.getBlockCountLong();
} else {
return statFs.getBlockCount();
}
}