Some mobile phone butler software can show the current system memory usage of how much, this number is obtained by the total memory size, minus the available memory size, and then the total size of the results, the following code can calculate how much memory used.
/** * Calculates the percentage of memory used * */public static string Getusedpercentvalue (context context) {String dir = "/proc/meminfo"; try {Filerea Der FR = new FileReader (dir); BufferedReader br = new BufferedReader (FR, 2048); String memoryline = Br.readline (); String submemoryline = memoryline.substring (Memoryline.indexof ("Memtotal:")); Br.close (); Long totalmemorysize = Integer.parseint (Submemoryline.replaceall ("\\d+", "")); Long availablesize = getavailablememory (context)/1024;int Percent = (int) ((totalmemorysize-availablesize)/(float) totalmemorysize *); return percent + "%";} catch (IOException e) {e.printstacktrace ();} Return "no results";} /** * Gets the current available memory and returns the data in bytes. * @return currently available memory. */private Static long Getavailablememory (context context) {Activitymanager.memoryinfo mi = new Activitymanager.memoryinfo (); Getactivitymanager (context) Getmemoryinfo (MI); return mi.availmem;}