獲得內存卡的剩餘內存

public static boolean hasStorageUsage() {
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        float freeStorage = (availableBlocks * blockSize)/(1024 * 1024);
        if (freeStorage >= minStorageUsage) {
               return true;
        }
        return false;
    }
註:package android.os.StatFs.java;
作者:hahashui123

發佈留言