get Available External Storage - Android android.os

Android examples for android.os:External Storage

Description

get Available External Storage

Demo Code

import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import java.io.File;

public class Main{

    public static long getAvailableExternalStorage() {
        try {//from   ww  w .j a  va 2s  .com
            File file = Environment.getExternalStorageDirectory();
            if (file != null && file.exists()) {
                StatFs sdFs = new StatFs(file.getPath());
                if (sdFs != null) {
                    long sdBlockSize = sdFs.getBlockSize();
                    long sdAvailCount = sdFs.getAvailableBlocks();
                    return sdAvailCount * sdBlockSize;
                }
            }
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

}

Related Tutorials