I want to retrieve the ram usage of an other app and display it in my app. How to do that ?
Asked
Active
Viewed 429 times
2 Answers
2
You can get the memory info using
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
and for a particular process use
activityManager.getProcessMemoryInfo(new int[]{process_ids});
which returns an array of memory information
getRunningAppProcesses will get you a list of PIDs, and then getProcessMemoryInfo will give you memory details about them.
sources : https://stackoverflow.com/a/13244684/6380895 https://stackoverflow.com/a/5963828/6380895 https://developer.android.com/reference/android/app/ActivityManager.html

zelite
- 1,478
- 16
- 37

Yohan Dahmani
- 1,670
- 21
- 33
1
MemoryInfo memory_info = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
double availableMegs = memory_info.availMem / 0x100000L;
//Percentage can be calculated for API 16+
double percentAvail = memory_info.availMem / (double)memory_info.totalMem * 100.0;
This will give you memory usage in percentage.

my bytecode
- 404
- 1
- 4
- 14
-
You want memory usage of particular app ? for example - Facebook. – my bytecode Feb 25 '20 at 12:59