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


Java StatFs.getBlockSizeLong方法代码示例

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


在下文中一共展示了StatFs.getBlockSizeLong方法的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);
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:29,代码来源:RootToolsInternalMethods.java

示例2: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:StatFsHelper.java

示例3: 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();
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:21,代码来源:SDCardUtils.java

示例4: 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();
}
 
开发者ID:chemickypes,项目名称:Glitchy,代码行数:22,代码来源:AbstractDiskStorage.java

示例5: 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();
  }
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:16,代码来源:CommonUtil.java

示例6: getSDcardAvailableSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SDka可用空间
 *
 * @return
 */
private static long getSDcardAvailableSize()
{

    if (checkSdCard())
    {
        File path = Environment.getExternalStorageDirectory();
        StatFs mStatFs = new StatFs(path.getPath());
        long blockSizeLong = mStatFs.getBlockSizeLong();
        long availableBlocksLong = mStatFs.getAvailableBlocksLong();
        return blockSizeLong * availableBlocksLong;
    } else
        return 0;
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:19,代码来源:CommonUtil.java

示例7: getFreeSpace

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SD卡剩余空间
 *
 * @return SD卡剩余空间
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getFreeSpace() {
    if (!isSDCardEnable()) return null;
    StatFs stat = new StatFs(getSDCardPath());
    long blockSize, availableBlocks;
    availableBlocks = stat.getAvailableBlocksLong();
    blockSize = stat.getBlockSizeLong();
    return ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize);
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:15,代码来源:SDCardUtils.java

示例8: getSDcardAvailableSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SDka可用空间
 */
private static long getSDcardAvailableSize() {

  if (checkSdCard()) {
    File path = Environment.getExternalStorageDirectory();
    StatFs mStatFs = new StatFs(path.getPath());
    long blockSizeLong = mStatFs.getBlockSizeLong();
    long availableBlocksLong = mStatFs.getAvailableBlocksLong();
    return blockSizeLong * availableBlocksLong;
  } else {
    return 0;
  }
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:16,代码来源:CommonUtil.java

示例9: getAvailableStorage

import android.os.StatFs; //导入方法依赖的package包/类
public static long getAvailableStorage() {
    try {
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
        } else {
            return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        }
    } catch (RuntimeException ex) {
        return 0;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:UpdateDownloader.java

示例10: getFreeSpace

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取SD卡剩余空间
 *
 * @return SD卡剩余空间
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static String getFreeSpace() {
    if (!isSDCardEnable()) return "sdcard unable!";
    StatFs stat = new StatFs(getSDCardPath());
    long blockSize, availableBlocks;
    availableBlocks = stat.getAvailableBlocksLong();
    blockSize = stat.getBlockSizeLong();
    return ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:15,代码来源:SDCardUtils.java

示例11: getBlockSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * See {@link android.os.StatFs#getBlockSize()}.
 */
@SuppressWarnings("deprecation")
public static long getBlockSize(StatFs statFs) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return statFs.getBlockSizeLong();
    } else {
        return statFs.getBlockSize();
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:12,代码来源:ApiCompatibilityUtils.java

示例12: getDirUsedSize

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * 获取目录空间已用容量
 *
 * @param dirPath 目录路径
 *
 * @return 容量(Byte)
 */
public static long getDirUsedSize(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 totalBlocks;
		if (Build.VERSION.SDK_INT < 18) {
			totalBlocks = statFs.getBlockCount();
		} else {
			totalBlocks = statFs.getBlockCountLong();
		}
		
		// 获取空闲数据块的数量
		long availableBlocks;
		if (Build.VERSION.SDK_INT < 18) {
			availableBlocks = statFs.getAvailableBlocks();
		} else {
			availableBlocks = statFs.getAvailableBlocksLong();
		}
		
		return Math.abs((totalBlocks - availableBlocks) * blocSize);
	} catch (Throwable e) {
		DLog.e(e);
	}
	return 0;
}
 
开发者ID:youmi,项目名称:nativead,代码行数:47,代码来源:FileUtils.java

示例13: computeSpace

import android.os.StatFs; //导入方法依赖的package包/类
private void computeSpace() {
  StatFs stat = new StatFs(mountPoint);
  long bytesAvailable;
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
    bytesAvailable = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
  } else {
    //noinspection deprecation
    bytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
  }
  // Convert total bytes to megabytes
  freeSpace = Math.round(bytesAvailable / (1024 * 1024));
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:13,代码来源:StorageUtils.java

示例14: getFreeSpaceSize

import android.os.StatFs; //导入方法依赖的package包/类
public static Long getFreeSpaceSize(StatFs statFs) {
    long freeSpaceSize = 0;
    try {
        if (VERSION.SDK_INT >= 18) {
            freeSpaceSize = statFs.getFreeBlocksLong() * statFs.getBlockSizeLong();
        } else {
            freeSpaceSize = ((long) statFs.getFreeBlocks()) * ((long) statFs.getBlockSize());
        }
    } catch (Throwable e) {
        LOG.w(TAG, "getScreenHeightWidth failed(Throwable): " + e.getMessage());
    }
    return Long.valueOf(freeSpaceSize);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:SDKUtils.java

示例15: getSDCardInfo

import android.os.StatFs; //导入方法依赖的package包/类
/**
 * Get SD card info detail.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static SDCardInfo getSDCardInfo() {
    SDCardInfo sd = new SDCardInfo();
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        sd.isExist = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            File sdcardDir = Environment.getExternalStorageDirectory();
            StatFs sf = new StatFs(sdcardDir.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();
        }
    }
    if (Log.isPrint) {
        Log.i(TAG, sd.toString());
    }
    return sd;
}
 
开发者ID:androidDaniel,项目名称:treasure,代码行数:31,代码来源:SdCardUtil.java


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