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


Java StatFs.getBlockCount方法代码示例

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


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

示例1: 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;
}
 
开发者ID:CodingCodersCode,项目名称:EvolvingNetLib,代码行数:27,代码来源:SDCardUtil.java

示例2: t

import android.os.StatFs; //导入方法依赖的package包/类
public static String t(Context context) {
    try {
        if (a(context, "android.permission.WRITE_EXTERNAL_STORAGE")) {
            String externalStorageState = Environment.getExternalStorageState();
            if (externalStorageState == null || !externalStorageState.equals("mounted")) {
                return null;
            }
            externalStorageState = Environment.getExternalStorageDirectory().getPath();
            if (externalStorageState == null) {
                return null;
            }
            StatFs statFs = new StatFs(externalStorageState);
            long blockCount = (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize
                    ())) / 1000000;
            return String.valueOf((((long) statFs.getBlockSize()) * ((long) statFs
                    .getAvailableBlocks())) / 1000000) + "/" + String.valueOf(blockCount);
        }
        f.warn("can not get the permission of android.permission.WRITE_EXTERNAL_STORAGE");
        return null;
    } catch (Object th) {
        f.e(th);
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:k.java

示例3: getTotalSpaceByPath

import android.os.StatFs; //导入方法依赖的package包/类
public static long getTotalSpaceByPath(String path) {
    Exception e;
    if (TextUtils.isEmpty(path)) {
        return -1;
    }
    File dir = new File(path);
    if (!dir.exists()) {
        dir.mkdir();
    }
    long block = 0;
    long size = 0;
    try {
        StatFs statFs = new StatFs(path);
        StatFs statFs2;
        try {
            block = (long) statFs.getBlockCount();
            size = (long) statFs.getBlockSize();
            statFs2 = statFs;
        } catch (Exception e2) {
            e = e2;
            statFs2 = statFs;
            e.printStackTrace();
            return size * block;
        }
    } catch (Exception e3) {
        e = e3;
        e.printStackTrace();
        return size * block;
    }
    return size * block;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:32,代码来源:StoreUtils.java

示例4: ax

import android.os.StatFs; //导入方法依赖的package包/类
public static String ax() {
    if (e(cC)) {
        return cC;
    }
    StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
    long blockCount = (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) /
            1000000;
    StatFs statFs2 = new StatFs(Environment.getDataDirectory().getPath());
    String str = String.valueOf((((long) statFs2.getAvailableBlocks()) * ((long) statFs2
            .getBlockSize())) / 1000000) + "/" + String.valueOf(blockCount);
    cC = str;
    return str;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:l.java

示例5: getInternalStorageSize

import android.os.StatFs; //导入方法依赖的package包/类
public static long getInternalStorageSize(Context context) {
    long j = 0;
    try {
        String[] paths = (String[]) StorageManager.class.getMethod("getVolumePaths", new Class[0]).invoke((StorageManager) context.getSystemService("storage"), new Object[0]);
        if (paths != null && paths.length >= 1) {
            StatFs statFs = new StatFs(paths[0]);
            j = ((((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024) / 1024;
        }
    } catch (Exception e) {
        LogTool.e(TAG, "getInternalStorageSize. " + e.toString());
    }
    return j;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:DeviceUtils.java

示例6: getTotalSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SD卡总的容量
 * @return 总容量;-1:SD卡不可用
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static long getTotalSize(){
	if(isAvailable()){
		StatFs statFs = new StatFs(getRootDirectory().getPath());
		if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1){
			return statFs.getBlockCount() * statFs.getBlockSize();
		}else{
			return statFs.getBlockCount() * statFs.getBlockSize();
		}
	}else{
		return -1;
	}
}
 
开发者ID:Catslovetoplaygames,项目名称:MVP,代码行数:18,代码来源:SDCardUtils.java

示例7: getSDCardSize

import android.os.StatFs; //导入方法依赖的package包/类
public String getSDCardSize() {
    long j = 0;
    try {
        if ("mounted".equals(Environment.getExternalStorageState())) {
            StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
            j = ((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize());
        }
    } catch (Exception e) {
    }
    return String.valueOf(j);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:DeviceInfo.java

示例8: getMinimumDelete

import android.os.StatFs; //导入方法依赖的package包/类
private long getMinimumDelete(List<File> files)
{
	if (files.isEmpty())
	{
		return 0L;
	}

	long cacheSizeBytes = Util.getCacheSizeMB(context) * 1024L * 1024L;
	long bytesUsedBySubsonic = 0L;

	for (File file : files)
	{
		bytesUsedBySubsonic += file.length();
	}

	// Ensure that file system is not more than 95% full.
	StatFs stat = new StatFs(files.get(0).getPath());
	long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize();
	long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
	long bytesUsedFs = bytesTotalFs - bytesAvailableFs;
	long minFsAvailability = bytesTotalFs - MIN_FREE_SPACE;

	long bytesToDeleteCacheLimit = Math.max(bytesUsedBySubsonic - cacheSizeBytes, 0L);
	long bytesToDeleteFsLimit = Math.max(bytesUsedFs - minFsAvailability, 0L);
	long bytesToDelete = Math.max(bytesToDeleteCacheLimit, bytesToDeleteFsLimit);

	Log.i(TAG, String.format("File system       : %s of %s available", Util.formatBytes(bytesAvailableFs), Util.formatBytes(bytesTotalFs)));
	Log.i(TAG, String.format("Cache limit       : %s", Util.formatBytes(cacheSizeBytes)));
	Log.i(TAG, String.format("Cache size before : %s", Util.formatBytes(bytesUsedBySubsonic)));
	Log.i(TAG, String.format("Minimum to delete : %s", Util.formatBytes(bytesToDelete)));

	return bytesToDelete;
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:34,代码来源:CacheCleaner.java

示例9: getSDTotalSize

import android.os.StatFs; //导入方法依赖的package包/类
private String getSDTotalSize()
{
       File path = Environment.getExternalStorageDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long totalBlocks = stat.getBlockCount();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:9,代码来源:SimpleActivity.java

示例10: getRomTotalSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
    * 获得机身内存总大小
    *
    * @return
    */
   private String getRomTotalSize()
{
       File path = Environment.getDataDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long totalBlocks = stat.getBlockCount();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:14,代码来源:SimpleActivity.java

示例11: 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

示例12: 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:pooyafaroka,项目名称:PlusGram,代码行数:15,代码来源:DocumentSelectActivity.java

示例13: calculateDiskCacheSize

import android.os.StatFs; //导入方法依赖的package包/类
private static long calculateDiskCacheSize(File dir) {
    long size = 0;
    try {
        if (!dir.exists()) {
            dir.mkdirs();
        }
        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:jeasinlee,项目名称:AndroidBasicLibs,代码行数:14,代码来源:DiskCache.java

示例14: getSdcardTotalSpace

import android.os.StatFs; //导入方法依赖的package包/类
public static long getSdcardTotalSpace() {
    Exception e;
    if (!isSdcardAvailable()) {
        return -1;
    }
    String sdcardPath = getDownloadDir().getAbsolutePath();
    File dir = new File(sdcardPath);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    long block = 0;
    long size = 0;
    try {
        StatFs statFs = new StatFs(sdcardPath);
        StatFs statFs2;
        try {
            block = (long) statFs.getBlockCount();
            size = (long) statFs.getBlockSize();
            statFs2 = statFs;
        } catch (Exception e2) {
            e = e2;
            statFs2 = statFs;
            e.printStackTrace();
            return size * block;
        }
    } catch (Exception e3) {
        e = e3;
        e.printStackTrace();
        return size * block;
    }
    return size * block;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:33,代码来源:StoreUtils.java

示例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();
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:12,代码来源:ApiCompatibilityUtils.java


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