internal Memory Used In Percent - Android android.os

Android examples for android.os:Memory

Description

internal Memory Used In Percent

Demo Code

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

public class Main {

  public static float internalMemoryUsedInPercent() {
    float total = internalMemoryTotal();
    float free = internalMemoryAvailable();
    float used = total - free;

    return used / total * 100;
  }//from  www  .ja  v  a2 s .c om

  public static float internalMemoryAvailable() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks();
    return bytesAvailable / (1024.f * 1024.f);
  }

  public static float internalMemoryTotal() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount();
    return bytesAvailable / (1024.f * 1024.f);
  }

}

Related Tutorials