I am working on an app, in which I need to display the total and available memory. I am using the following snippet; however, it works only on API 16 or above. I need something which works on all Android versions.
my question is Different from the "possible duplicates" as my question is to get memory usage on all api levels.
private void getAvailableRam() {
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
ttvv.setText(availableMegs + " MB");
}
private void getTotalRamSize() {
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long totalMemory = mi.totalMem / 1048576L;
ttvv2.setText(totalMemory + " MB");
}