get Device Available Memory - Android android.os

Android examples for android.os:Memory

Description

get Device Available Memory

Demo Code

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

public class Main {

  private static Application sApp;

  /**/*w w  w . j  a  va  2s  .  c  o  m*/
   * return device available memory
   */
  public static int getDeviceAvailableMemory() {
    ActivityManager am = (ActivityManager) sApp.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);
    return (int) (mi.availMem / (1024 * 1024));
  }

}

Related Tutorials