get Available Internal Memory Size - Android android.os

Android examples for android.os:Memory

Description

get Available Internal Memory Size

Demo Code

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

public class Main {

  public static long getAvailableInternalMemorySize() {
    long availableSpace = -1l;
    try {/*from w w w .j  a  v  a  2s. c  o  m*/
      String path = Environment.getDataDirectory().getPath();
      StatFs stat = new StatFs(path);
      long blockSize = stat.getBlockSize();
      long availableBlocks = stat.getAvailableBlocks();

      availableSpace = availableBlocks * blockSize;
    } catch (Exception e) {
    }
    return availableSpace;
  }

}

Related Tutorials