get Available Memory and use Formatter to format the value - Android android.os

Android examples for android.os:Memory

Description

get Available Memory and use Formatter to format the value

Demo Code

import android.app.ActivityManager;
import android.content.Context;
import android.text.format.Formatter;

public class Main {

  public static String getAvailMemory(Context context) {

    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();

    am.getMemoryInfo(mi);//  ww  w  . ja v a  2  s .c o  m
    return Formatter.formatFileSize(context, mi.availMem);

  }

}

Related Tutorials