Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
750 views
in Technique[技术] by (71.8m points)

api - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...