本文整理汇总了Java中android.os.StatFs类的典型用法代码示例。如果您正苦于以下问题:Java StatFs类的具体用法?Java StatFs怎么用?Java StatFs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatFs类属于android.os包,在下文中一共展示了StatFs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasEnoughSpaceOnSdCard
import android.os.StatFs; //导入依赖的package包/类
/**
* Checks if there is enough Space on SDCard
*
* @param updateSize size to Check (long)
* @return <code>true</code> if the Update will fit on SDCard, <code>false</code> if not enough
* space on SDCard. Will also return <code>false</code>, if the SDCard is not mounted as
* read/write
*/
@SuppressWarnings("deprecation")
public boolean hasEnoughSpaceOnSdCard(long updateSize) {
RootTools.log("Checking SDcard size and that it is mounted as RW");
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
return false;
}
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = 0;
long availableBlocks = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSize();
availableBlocks = stat.getAvailableBlocks();
} else {
blockSize = stat.getBlockSizeLong();
availableBlocks = stat.getAvailableBlocksLong();
}
return (updateSize < availableBlocks * blockSize);
}
示例2: checkRomSpaceEnough
import android.os.StatFs; //导入依赖的package包/类
@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;
}
if (allSize != 0 && availableSize > limitSize) {
return true;
}
return false;
}
示例3: 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);
}
示例4: 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;
}
示例5: getStatFsSize
import android.os.StatFs; //导入依赖的package包/类
private static long getStatFsSize(StatFs statFs, String blockSizeMethod, String availableBlocksMethod) {
try {
Method getBlockSizeMethod = statFs.getClass().getMethod(blockSizeMethod);
getBlockSizeMethod.setAccessible(true);
Method getAvailableBlocksMethod = statFs.getClass().getMethod(availableBlocksMethod);
getAvailableBlocksMethod.setAccessible(true);
long blockSize = (Long) getBlockSizeMethod.invoke(statFs);
long availableBlocks = (Long) getAvailableBlocksMethod.invoke(statFs);
return blockSize * availableBlocks;
} catch (Throwable e) {
OkLogger.printStackTrace(e);
}
return 0;
}
示例6: getAvailableStorageSpace
import android.os.StatFs; //导入依赖的package包/类
/**
* Gets the information about the available storage space
* either internal or external depends on the give input
* @param storageType Internal or external storage type
* @return available space in bytes, 0 if no information is available
*/
@SuppressLint("DeprecatedMethod")
public long getAvailableStorageSpace(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.getAvailableBlocksLong();
} else {
blockSize = statFS.getBlockSize();
availableBlocks = statFS.getAvailableBlocks();
}
return blockSize * availableBlocks;
}
return 0;
}
示例7: 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();
}
示例8: 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;
}
示例9: getSDCardAvailableSize
import android.os.StatFs; //导入依赖的package包/类
/**
* 获取SD卡可用剩余空间大小(还剩下多少空间)
*
* @return
*/
public static long getSDCardAvailableSize() {
long availableBlockCount;
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) {
availableBlockCount = statFs.getAvailableBlocksLong();//有多少块
blockSize = statFs.getBlockSizeLong();//每块有多大
} else {
availableBlockCount = statFs.getAvailableBlocks();//有多少块
blockSize = statFs.getBlockSize();//每块有多大
}
return availableBlockCount * blockSize / 1024 / 1024; //总大小
}
return 0;
}
示例10: getStatFsSize
import android.os.StatFs; //导入依赖的package包/类
private static long getStatFsSize(StatFs statFs, String blockSizeMethod, String availableBlocksMethod) {
try {
Method getBlockSizeMethod = statFs.getClass().getMethod(blockSizeMethod);
getBlockSizeMethod.setAccessible(true);
Method getAvailableBlocksMethod = statFs.getClass().getMethod(availableBlocksMethod);
getAvailableBlocksMethod.setAccessible(true);
long blockSize = (Long) getBlockSizeMethod.invoke(statFs);
long availableBlocks = (Long) getAvailableBlocksMethod.invoke(statFs);
return blockSize * availableBlocks;
} catch (Throwable e) {
e.printStackTrace();
}
return 0;
}
示例11: isAvaiableSpace
import android.os.StatFs; //导入依赖的package包/类
/**
* 判断存储空间大小是否满足条件
*
* @param sizeByte
* @return
*/
public static boolean isAvaiableSpace(float sizeByte) {
boolean ishasSpace = false;
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
String sdcard = Environment.getExternalStorageDirectory().getPath();
StatFs statFs = new StatFs(sdcard);
long blockSize = statFs.getBlockSize();
long blocks = statFs.getAvailableBlocks();
float availableSpare = blocks * blockSize;
if (availableSpare > (sizeByte + 1024 * 1024)) {
ishasSpace = true;
}
}
return ishasSpace;
}
示例12: getAvailableBytes
import android.os.StatFs; //导入依赖的package包/类
/**
* Return number of available bytes on the filesystem backing the given
* {@link FileDescriptor}, minus any {@link #RESERVED_BYTES} buffer.
*/
private static long getAvailableBytes(FileDescriptor fd) throws IOException {
try {
//TODO only Sdcard check??
String sdcardDir = Environment.getExternalStorageDirectory().getPath();
StatFs stat = new StatFs(sdcardDir);
long bytesAvailable = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
bytesAvailable = (long)stat.getBlockSizeLong() * (long)stat.getAvailableBlocksLong();
} else {
bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
}
return bytesAvailable - RESERVED_BYTES;
} catch (Exception e) {
throw new IOException("getAvailableBytes IOException");
}
}
示例13: checkRomSpaceEnough
import android.os.StatFs; //导入依赖的package包/类
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
long allSize;
long availableSize = 0;
try {
StatFs sf = new StatFs(Environment.getDataDirectory().getPath());
availableSize = ((long) sf.getAvailableBlocks()) * ((long) sf.getBlockSize());
allSize = ((long) sf.getBlockCount()) * ((long) sf.getBlockSize());
} catch (Exception e) {
allSize = 0;
}
if (allSize == 0 || availableSize <= limitSize) {
return false;
}
return true;
}
示例14: getStorageAvailableSize
import android.os.StatFs; //导入依赖的package包/类
private long getStorageAvailableSize(Context context)
{
try
{
statFS = new StatFs(storagePath);
long storageAvailableBlocks = (long)statFS.getBlockSize() * (long)statFS.getAvailableBlocks();
statFS = null;
return storageAvailableBlocks;
}
catch (Exception e)
{
Log.w("MonitoringManager", "getStorageAvailableSize : " + context.getString(R.string.log_monitoring_manager_error_get_storage_available_size) + " : " + e);
databaseManager.insertLog(context, "" + context.getString(R.string.log_monitoring_manager_error_get_storage_available_size), new Date().getTime(), 2, false);
return 0;
}
}
示例15: 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();
}