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.
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.
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;
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With