1 /** Phone Total memory * /2 PrivateString gettotalmemory () {3 //system memory information file4String str1 = "/proc/meminfo";5 String str2;6 string[] arrayofstring;7 LongInitial_memory = 0;8 9 Try {TenFileReader Localfilereader =NewFileReader (str1); OneBufferedReader Localbufferedreader =NewBufferedReader ( ALocalfilereader, 8192); - //read Meminfo First line, total system memory size -STR2 =localbufferedreader.readline (); the -arrayofstring = Str2.split ("\\s+"); - for(String num:arrayofstring) { -LOG.I (str2, num + "\ T"); + } - //gets the total system memory, in kilobytes, multiplied by 1024 to byte +Initial_memory = integer.valueof (Arrayofstring[1]). Intvalue () * 1024; A localbufferedreader.close (); at}Catch(IOException e) { - } - //byte converted to KB or MB, memory size normalized - returnformatter.formatfilesize (Getbasecontext (), initial_memory); -}
1 /** Get the current available memory size for Android * / 2 PrivateString getavailmemory () {3Activitymanager am =(Activitymanager) Getsystemservice (
Context.activity_service);4Memoryinfo mi =Newmemoryinfo ();5 Am.getmemoryinfo (MI);6 //Mi.availmem; available memory for the current system7 //normalize the acquired memory size8 returnformatter.formatfilesize (Getbasecontext (), mi.availmem);9}
1/** Android Gets the amount of memory the app occupies * /2Private voidGetrunningappprocessinfo () {3Activitymanager Mactivitymanager =(Activitymanager) Getsystemservice (4 context.activity_service);5 6 //get all the processes running in the system7List<runningappprocessinfo> runningappprocesseslist =Mactivitymanager8 . getrunningappprocesses ();9 Ten for(Runningappprocessinfo runningappprocessinfo:runningappprocesseslist) { One //Process ID Number A intPID =Runningappprocessinfo.pid; - //User ID - intUID =Runningappprocessinfo.uid; the //Process Name -String ProcessName =Runningappprocessinfo.processname; - //memory occupied by - int[] PIDs =New int[] {pid}; +debug.memoryinfo[] Memoryinfo =Mactivitymanager - . Getprocessmemoryinfo (PIDs); + intMemorysize = memoryinfo[0].dalvikprivatedirty; A atLOG.I (TAG, "processname=" + ProcessName + ", pid=" + pid + ", uid=" -+ UID + ", memorysize=" + memorysize + "KB"); - } -}
1 /**2 * Get a single app memory limit size3 * Returns the number in M,4 * may not have the same value on different platforms or devices5 */6 Private voidtest01 () {7Activitymanager ActivityManager2 =(Activitymanager) Getsystemservice (8 context.activity_service);9 Activitymanager2.getmemoryclass ();Ten}
Get phone memory \ Free memory \ Single app running memory