android获取外置SD卡可用空间大小

    // 获取外置SD卡的可用空间大小
    public static long getWaiZhiSDCardAvailableSize(String rootPath) {
        if (isSDCardMounted()) {
            StatFs fs = new StatFs(rootPath);
            long count = fs.getAvailableBlocksLong();
            long size = fs.getBlockSizeLong();
            return count * size / 1024 / 1024;
        }
        return 0;
    }

  其中rootPath是外置sd卡的根目录,返回的是MB

posted on 2018-09-11 14:36  endian11  阅读(293)  评论(0编辑  收藏  举报

导航