当前位置:操作系统 > 安卓/Android >>

获得内存卡的剩余内存

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
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,