Get phone memory \ Free memory \ Single app running memory

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.