get Total Memory by SDK version - Android android.os

Android examples for android.os:Memory

Description

get Total Memory by SDK version

Demo Code

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

public class Main {

  public static long getTotalMemory(Context context) {
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    am.getMemoryInfo(memoryInfo);//from  w  ww  . ja va 2s. co  m

    if (Build.VERSION.SDK_INT > 15) {
      return memoryInfo.totalMem / (1024 * 1024);
    } else {
      return 0;
    }
  }

}

Related Tutorials