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


Java StatFs.getAvailableBlocksLong方法代碼示例

本文整理匯總了Java中android.os.StatFs.getAvailableBlocksLong方法的典型用法代碼示例。如果您正苦於以下問題:Java StatFs.getAvailableBlocksLong方法的具體用法?Java StatFs.getAvailableBlocksLong怎麽用?Java StatFs.getAvailableBlocksLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.StatFs的用法示例。


在下文中一共展示了StatFs.getAvailableBlocksLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFreeSpace

import android.os.StatFs; //導入方法依賴的package包/類
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public long getFreeSpace(SizeUnit sizeUnit) {
	String path = buildAbsolutePath();
	StatFs statFs = new StatFs(path);
	long availableBlocks;
	long blockSize;
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
		availableBlocks = statFs.getAvailableBlocks();
		blockSize = statFs.getBlockSize();
	} else {
		availableBlocks = statFs.getAvailableBlocksLong();
		blockSize = statFs.getBlockSizeLong();
	}
	long freeBytes = availableBlocks * blockSize;
	return freeBytes / sizeUnit.inBytes();
}
 
開發者ID:chemickypes,項目名稱:Glitchy,代碼行數:19,代碼來源:AbstractDiskStorage.java

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

示例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:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:21,代碼來源:SDCardUtils.java

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

示例5: 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:angcyo,項目名稱:RLibrary,代碼行數:21,代碼來源:SDCardUtils.java

示例6: 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:AlexanderKirillov,項目名稱:Script-Executor-ROOT,代碼行數:29,代碼來源:RootToolsInternalMethods.java

示例7: 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();
        }
    }

        Log.i(TAG, sd.toString());

    return sd;
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:31,代碼來源:SdCardUtil.java

示例8: getAvailableSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * Get available size of SD card.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getAvailableSize(String path) {
    try {
        File base = new File(path);
        StatFs stat = new StatFs(base.getPath());
        return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:15,代碼來源:SdCardUtil.java

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

示例10: 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:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:15,代碼來源:SDCardUtils.java

示例11: 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:yufeilong92,項目名稱:update-master,代碼行數:13,代碼來源:UpdateDownloader.java

示例12: getDirSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲取某個目錄可用大小.
 */
@SuppressLint({"NewApi", "ObsoleteSdkInt"})
@SuppressWarnings("deprecation")
public static long getDirSize(String path) {
    StatFs stat = new StatFs(path);
    long blockSize, availableBlocks;
    if (Build.VERSION.SDK_INT >= 18) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();
    }
    return availableBlocks * blockSize;
}
 
開發者ID:ChunweiDu,項目名稱:Utils,代碼行數:18,代碼來源:FileUtil.java

示例13: getPhoneAvailableSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲取手機內存存儲可用空間
 */
public static long getPhoneAvailableSize() {

  if (!checkSdCard()) {
    File path = Environment.getDataDirectory();
    StatFs mStatFs = new StatFs(path.getPath());
    long blockSizeLong = mStatFs.getBlockSizeLong();
    long availableBlocksLong = mStatFs.getAvailableBlocksLong();
    return blockSizeLong * availableBlocksLong;
  } else
    return getSDcardAvailableSize();
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:15,代碼來源:CommonUtil.java

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

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


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