get available memory and log - Android Hardware

Android examples for Hardware:Memory

Description

get available memory and log

Demo Code


//package com.java2s;
import android.app.ActivityManager;

import android.content.Context;

import android.util.Log;

public class Main {
    private final static String TAG_SYSTEM_UTIL = "SystemUtil";

    /**//from  www . ja  v a2 s .c o m
     * get available memory
     *
     * @param context
     * @return available memory?MB?
     */
    public static long getAvailableMemory(Context context) {
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        am.getMemoryInfo(memoryInfo);

        Log.d(TAG_SYSTEM_UTIL, "before clear the memory is "
                + memoryInfo.availMem / (1024 * 1024));

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

Related Tutorials