Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How do you get total memory RAM in the device?

I can get total available memory by:

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
memoryInfo.availMem;

However, how do you get Total memory (RAM) of the device?

I did read: How do I discover memory usage of my application in Android?

It doesn't seem like adding pidMemoryInfo.getTotalPss() gives me the total memory either.

like image 571
jclova Avatar asked Oct 22 '10 16:10

jclova


People also ask

How do I find out how much RAM my phone is using?

Depending on your phone model, tap System > Memory or tap Memory in Settings to see how much memory is available and how your phone's memory is being used. You can also find out how individual apps are using memory. Tap Memory used by apps to find out the memory usage for apps.


2 Answers

Try this works for me.

public static String getTotalRAM() {
    RandomAccessFile reader = null;
    String load = null;
    try {
        reader = new RandomAccessFile("/proc/meminfo", "r");
        load = reader.readLine();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        // Streams.close(reader);
    }
    return load;
}
like image 112
sandy Avatar answered Oct 06 '22 00:10

sandy


If you don't find something else, you could bypass android and read /proc/meminfo which is what the 'free' command on a more ordinary linux distribution does

like image 27
Chris Stratton Avatar answered Oct 06 '22 01:10

Chris Stratton