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