当前位置: 首页>>代码示例>>Java>>正文


Java StatFs.getBlockSize方法代码示例

本文整理汇总了Java中android.os.StatFs.getBlockSize方法的典型用法代码示例。如果您正苦于以下问题:Java StatFs.getBlockSize方法的具体用法?Java StatFs.getBlockSize怎么用?Java StatFs.getBlockSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.StatFs的用法示例。


在下文中一共展示了StatFs.getBlockSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAvailableExternalMemorySize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取手机外部可用空间大小,字节
 * 
 * @return
 */
public static long getAvailableExternalMemorySize()
{
    if (externalMemoryAvailable())
    {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    }
    else
    {
        return -1;
    }
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:21,代码来源:MIP_DeviceInfoUtils.java

示例2: getSDAvailableSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 得到sd卡剩余大小
 *
 * @return
 */
public static long getSDAvailableSize() {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = 0;
    long availableBlocks = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();
    }

    return blockSize * availableBlocks / 1024;
}
 
开发者ID:TAnsz,项目名称:MyTvLauncher,代码行数:21,代码来源:Tools.java

示例3: 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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:Utils.java

示例4: getRootSubtitle

import android.os.StatFs; //导入方法依赖的package包/类
private String getRootSubtitle(String path) {
    try {
        StatFs stat = new StatFs(path);
        long total = (long)stat.getBlockCount() * (long)stat.getBlockSize();
        long free = (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
        if (total == 0) {
            return "";
        }
        return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return path;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:15,代码来源:DocumentSelectActivity.java

示例5: getRomAvailableSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获得机身可用内存rom
 * 
 * @return
 */
public static long getRomAvailableSize() {
	File path = Environment.getDataDirectory();
	StatFs stat = new StatFs(path.getPath());
	long blockSize = stat.getBlockSize();
	long availableBlocks = stat.getAvailableBlocks();
	return blockSize * availableBlocks;
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:13,代码来源:SdCardUtils.java

示例6: getSDSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SD卡剩余空间的大小
 * 
 * @return long SD卡剩余空间的大小(单位:byte)
 */
public static long getSDSize()
{
    final String str = Environment.getExternalStorageDirectory().getPath();
    final StatFs localStatFs = new StatFs(str);
    final long blockSize = localStatFs.getBlockSize();
    return localStatFs.getAvailableBlocks() * blockSize;
}
 
开发者ID:BaoBaoJianqiang,项目名称:AndroidNetwork,代码行数:13,代码来源:BaseUtils.java

示例7: calculateDiskCacheSize

import android.os.StatFs; //导入方法依赖的package包/类
static long calculateDiskCacheSize(File dir) {
        long size = MIN_DISK_CACHE_SIZE;

        try {
            StatFs statFs = new StatFs(dir.getAbsolutePath());
            long available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
            size = available / 50;
        } catch (IllegalArgumentException ignored) {
        }

//        return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
        return 40772;
    }
 
开发者ID:IstiN,项目名称:android-training-2017,代码行数:14,代码来源:BaseDiskCache.java

示例8: getFreeBytes

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取指定路径所在空间的剩余可用容量字节数(byte)
 * @param filePath
 * @return 容量字节 SDCard可用空间,内部存储可用空间
 */
public long getFreeBytes(String filePath) {
    // 如果是sd卡的下的路径,则获取sd卡可用容量
    if (filePath.startsWith(getSDCardPath())) {
        filePath = getSDCardPath();
    } else {// 如果是内部存储的路径,则获取内存存储的可用容量
        filePath = Environment.getDataDirectory().getAbsolutePath();
    }
    StatFs stat = new StatFs(filePath);
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:17,代码来源:SDCardUtils.java

示例9: getDirTotalSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取目录空间总容量
 *
 * @param dirPath 目录路径
 *
 * @return 容量(Byte)
 */
public static long getDirTotalSize(String dirPath) {
	try {
		if (TextUtils.isEmpty(dirPath)) {
			return 0;
		}
		StatFs statFs = new StatFs(dirPath);
		
		// 获取单个数据块的大小(Byte)
		long blocSize;
		if (Build.VERSION.SDK_INT < 18) {
			blocSize = statFs.getBlockSize();
		} else {
			blocSize = statFs.getBlockSizeLong();
		}
		
		// 获取所有数据块的数量
		long countBlock;
		if (Build.VERSION.SDK_INT < 18) {
			countBlock = statFs.getBlockCount();
		} else {
			countBlock = statFs.getBlockCountLong();
		}
		
		return Math.abs(countBlock * blocSize);
	} catch (Throwable e) {
		DLog.e(e);
	}
	return 0;
}
 
开发者ID:youmi,项目名称:nativead,代码行数:37,代码来源:FileUtils.java

示例10: calculateDiskCacheSize

import android.os.StatFs; //导入方法依赖的package包/类
private static long calculateDiskCacheSize(File dir) {
    long size = 0;
    try {
        StatFs statFs = new StatFs(dir.getAbsolutePath());
        long available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
        size = available / 50;
    } catch (IllegalArgumentException ignored) {
    }
    return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:11,代码来源:RxCache.java

示例11: getResidualSpace

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取目录剩余空间
 *
 * @param directoryPath
 * @return
 */
private long getResidualSpace(String directoryPath) {
    try {
        StatFs sf = new StatFs(directoryPath);
        long blockSize = sf.getBlockSize();
        long availCount = sf.getAvailableBlocks();
        long availCountByte = availCount * blockSize;
        return availCountByte;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:19,代码来源:ExternalStorage.java

示例12: e

import android.os.StatFs; //导入方法依赖的package包/类
public static long e() {
    if (b()) {
        return 0;
    }
    File externalStorageDirectory = Environment.getExternalStorageDirectory();
    if (externalStorageDirectory == null || TextUtils.isEmpty(externalStorageDirectory
            .getPath())) {
        return 0;
    }
    StatFs statFs = new StatFs(externalStorageDirectory.getPath());
    return (((long) statFs.getAvailableBlocks()) - 4) * ((long) statFs.getBlockSize());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:c.java

示例13: getRomTotalSize

import android.os.StatFs; //导入方法依赖的package包/类
public static String getRomTotalSize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:8,代码来源:IoUtils.java

示例14: getFreeBytes

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * Gets the remaining number of bytes of available capacity in the space in the specified path, in units byte
 *
 * @param filePath file path
 * @return Capacity bytes, SDCard, free space, internal storage, free space
 */
public static long getFreeBytes(String filePath) {
    // If it is the next path of the SD card, the available capacity of the SD card is obtained.
    if (filePath.startsWith(getSDCardPath())) {
        filePath = getSDCardPath();
    } else {// If the path is stored inside, the available capacity of obtaining memory.
        filePath = Environment.getDataDirectory().getAbsolutePath();
    }
    StatFs stat = new StatFs(filePath);
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}
 
开发者ID:Jusenr,项目名称:androidtools,代码行数:18,代码来源:SDCardUtils.java

示例15: getUsableSpace

import android.os.StatFs; //导入方法依赖的package包/类
public static long getUsableSpace(File path) {
    if (path == null) {
        return -1;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace()/1024/1024;
    } else {
        if (!path.exists()) {
            return 0;
        } else {
            final StatFs stats = new StatFs(path.getPath());
            return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks()/1024/1024;
        }
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:16,代码来源:FileUtils.java


注:本文中的android.os.StatFs.getBlockSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。