本文整理汇总了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();
}
}