get Available Memory and return MB - Android android.os

Android examples for android.os:Memory

Description

get Available Memory and return MB

Demo Code

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

public class Main {

  public static long getAvailableMemory(Context context) {
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    am.getMemoryInfo(memoryInfo);/*w w  w  .j  ava  2s  .c om*/

    return memoryInfo.availMem / (1024 * 1024);
  }

}

Related Tutorials