get Available Internal Storage - Android android.os

Android examples for android.os:Disk

Description

get Available Internal 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 getAvailableInternalStorage() {
        File file = Environment.getDataDirectory();
        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;
            }/*w ww.  jav  a 2s  . c o m*/
        }
        return 0;
    }

}

Related Tutorials