Some methods to get the total memory and available memory of android phones

Source: Internet
Author: User

There are many ways to get memory on the Internet. I have collected the following details and can refer to this old man's blog.

Method 1:

Http://blog.csdn.net/sxwyf248/archive/2010/11/02/5981251.aspx

Method 2:

I found it in a forum. A master uses the java reflection mechanism to obtain some information about the memory of the mobile phone.

The Code is as follows.

Public class GetFreeMem extends Activity {<br/>/** Called when the activity is first created. */<br/> @ Override <br/> public void onCreate (Bundle savedInstanceState) {<br/> super. onCreate (savedInstanceState); <br/> setContentView (R. layout. main); <br/> Method _ readProclines = null; <br/> try {<br/> Class procClass; <br/> procClass = Class. forName ("android. OS. process "); <br/> Class parameterTypes [] = New Class [] {String. class, String []. class, long []. class };< br/> _ readProclines = procClass. getMethod ("readProcLines", parameterTypes); <br/> Object arglist [] = new Object [3]; <br/> final String [] mMemInfoFields = new String [] {"MemTotal:", <br/> "MemFree:", "Buffers:", "Cached :"}; <br/> long [] mMemInfoSizes = new long [mMemInfoFields. length]; <br/> mMemInfoSizes [0] = 30; <br/> mMemInfoSizes [1] =- 30; <br/> arglist [0] = new String ("/proc/meminfo"); <br/> arglist [1] = mMemInfoFields; <br/> arglist [2] = mMemInfoSizes; <br/> if (_ readProclines! = Null) {<br/> _ readProclines. invoke (null, arglist); <br/> for (int I = 0; I <mMemInfoSizes. length; I ++) {<br/> Log. d ("GetFreeMem", mMemInfoFields [I] + ":" + mMemInfoSizes [I]/1024 ); <br/>}< br/>} catch (ClassNotFoundException e) {<br/> e. printStackTrace (); <br/>} catch (SecurityException e) {<br/> e. printStackTrace (); <br/>}catch (IllegalArgumentException e) {<br/> e. printStackTrace (); <br/>} catch (IllegalAccessException e) {<br/> e. printStackTrace (); <br/>} catch (InvocationTargetException e) {<br/> e. printStackTrace (); <br/>} catch (NoSuchMethodException e) {<br/> e. printStackTrace (); <br/>}< br/>} 

 

Effect

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.