get Total Internal Space - Android android.os

Android examples for android.os:Environment

Description

get Total Internal Space

Demo Code

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

public class Main {

  public static long getTotalInternalSpace() {
    long totalSpace = -1L;
    try {/*from   w  w  w.  jav a2s. c om*/
      String path = Environment.getDataDirectory().getPath();
      StatFs stat = new StatFs(path);
      long blockSize = stat.getBlockSize();
      long totalBlocks = stat.getBlockCount();
      totalSpace = totalBlocks * blockSize;
    } catch (Exception e) {
    }
    return totalSpace;
  }

}

Related Tutorials