當前位置: 首頁>>代碼示例>>Java>>正文


Java StatFs類代碼示例

本文整理匯總了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);
}
 
開發者ID:mosamabinomar,項目名稱:RootPGPExplorer,代碼行數:29,代碼來源:RootToolsInternalMethods.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:Utils.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:Utils.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:StatFsHelper.java

示例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;
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:17,代碼來源:IOUtils.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:StatFsHelper.java

示例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();
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:21,代碼來源:SDCardUtils.java

示例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;
}
 
開發者ID:mChenys,項目名稱:AndroidFFmpegCompress,代碼行數:24,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:CodingCodersCode,項目名稱:EvolvingNetLib,代碼行數:28,代碼來源:SDCardUtil.java

示例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;
}
 
開發者ID:CodingCodersCode,項目名稱:EvolvingNetLib,代碼行數:17,代碼來源:CCIOUtils.java

示例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;
}
 
開發者ID:Liuzhiyang94,項目名稱:ComponentProjectDemo,代碼行數:22,代碼來源:CommonUtils.java

示例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");
    }
}
 
開發者ID:limpoxe,項目名稱:Android-DownloadManager,代碼行數:21,代碼來源:StorageUtils.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:Utils.java

示例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;
      }
  }
 
開發者ID:vassela,項目名稱:AC2RD,代碼行數:21,代碼來源:MonitoringManager.java

示例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();
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:21,代碼來源:SDCardUtils.java


注:本文中的android.os.StatFs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。