get External Storage Total Space - Android Phone

Android examples for Phone:Storage

Description

get External Storage Total Space

Demo Code


//package com.java2s;

import android.os.Environment;
import android.os.StatFs;

public class Main {
    public static final int getExternalTotalSpace() {
        final String path = Environment.getExternalStorageDirectory()
                .getAbsolutePath();//from www.  ja  v a2 s  .  co  m
        final int mbytes = getTotalForFile(path);
        return mbytes;
    }

    private static final int getTotalForFile(String path) {
        final StatFs sf = new StatFs(path);
        final int blocks = sf.getBlockCount();
        final int blockSize = sf.getBlockSize();
        final int totalBytes = blocks * blockSize;
        return totalBytes;
    }
}

Related Tutorials