Android-System Information (memory, CPU, SD card, power, version) get

Source: Internet
Author: User

Memory (RAM)

The total memory size information of Android is stored in the system's/proc/meminfo file, which can be obtained by reading this file:

 Public voidgettotalmemory () {String str1= "/proc/meminfo"; String str2=""; Try{FileReader fr=NewFileReader (STR1); BufferedReader Localbufferedreader=NewBufferedReader (FR, 8192);  while((str2 = Localbufferedreader.readline ())! =NULL) {log.i (TAG,"---" +str2); }          } Catch(IOException e) {}}

The operating information is as follows:

05-30 08:05:14.807:info/-systeminfo-(1519):---memtotal:204876KB05-30 08:05:14.807:info/-systeminfo-(1519):---memfree:4596KB05-30 08:05:14.807:info/-systeminfo-(1519):---buffers:16020KB05-30 08:05:14.807:info/-systeminfo-(1519):---cached:82508KB05-30 08:05:14.807:info/-systeminfo-(1519):---swapcached:64KB05-30 08:05:14.807:info/-systeminfo-(1519):---active:137104KB05-30 08:05:14.807:info/-systeminfo-(1519):---inactive:41056KB05-30 08:05:14.807:info/-systeminfo-(1519):---swaptotal:65528KB05-30 08:05:14.817:info/-systeminfo-(1519):---swapfree:65368KB05-30 08:05:14.817:info/-systeminfo-(1519):---dirty:88KB05-30 08:05:14.817:info/-systeminfo-(1519):---writeback:0KB05-30 08:05:14.817:info/-systeminfo-(1519):---anonpages:79672KB05-30 08:05:14.817:info/-systeminfo-(1519):---mapped:38296KB05-30 08:05:14.817:info/-systeminfo-(1519):---slab:5768KB05-30 08:05:14.817:info/-systeminfo-(1519):---sreclaimable:1856KB05-30 08:05:14.827:info/-systeminfo-(1519):---sunreclaim:3912KB05-30 08:05:14.827:info/-systeminfo-(1519):---pagetables:8184KB05-30 08:05:14.827:info/-systeminfo-(1519):---nfs_unstable:0KB05-30 08:05:14.827:info/-systeminfo-(1519):---bounce:0KB05-30 08:05:14.827:info/-systeminfo-(1519):---commitlimit:167964KB05-30 08:05:14.827:info/-systeminfo-(1519):---committed_as:11771920KB05-30 08:05:14.827:info/-systeminfo-(1519):---vmalloctotal:761856KB05-30 08:05:14.827:info/-systeminfo-(1519):---vmallocused:83656KB05-30 08:05:14.827:info/-systeminfo-(1519):---vmallocchunk:674820 kB

The first line is the total memory size (that is, the amount of RAM the user can use)!

To get the current remaining memory (RAM) Size:

 public  long   Getavailmemory () {activitymanager am  = (Acti          Vitymanager) Mcontext.getsystemservice (Context.activity_service); Activitymanager.memoryinfo mi  = new            Activitymanager.memoryinfo ();          Am.getmemoryinfo (MI);       return   Mi.availmem; }

Rom Size

 Public Long[] Getrommemroy () {Long[] Rominfo =New Long[2]; //Total rom MemoryRominfo[0] =gettotalinternalmemorysize (); //Available ROM MemoryFile Path =environment.getdatadirectory (); StatFs Stat=NewStatFs (Path.getpath ()); LongBlockSize =stat.getblocksize (); LongAvailableblocks =stat.getavailableblocks (); rominfo[1] = BlockSize *availableblocks;          GetVersion (); returnRominfo; }         Public Longgettotalinternalmemorysize () {File path=environment.getdatadirectory (); StatFs Stat=NewStatFs (Path.getpath ()); LongBlockSize =stat.getblocksize (); LongTotalblocks =Stat.getblockcount (); returnTotalblocks *blockSize; }

Note the type, or there will be an overflow after multiplying. The size of the available internal storage cannot be passed getrootdirectory (); obtained, many of the previous online transmission was made with getrootdirectory (), I found that the value of the test was incorrect. To be based on getdatadirectory ();

SDcard size

 Public Long[] Getsdcardmemory () {Long[] sdcardinfo=New Long[2]; String State=environment.getexternalstoragestate (); if(Environment.MEDIA_MOUNTED.equals (state)) {File Sdcarddir=environment.getexternalstoragedirectory (); StatFs SF=NewStatFs (Sdcarddir.getpath ()); LongBsize =sf.getblocksize (); LongBcount =Sf.getblockcount (); LongAvailblocks =sf.getavailableblocks (); sdcardinfo[0] = bsize * BCOUNT;//Total sizeSDCARDINFO[1] = bsize * availblocks;//Available Sizes        }          returnSdcardinfo; }

Note the type, or there will be an overflow after multiplying.

battery charge                                                                                         

Private Broadcastreceiver batteryreceiver=New  broadcastreceiver () {          @Override          public void OnReceive (Context context, Intent Intent) {              int level = Intent.getintextra ("level", 0);               //level  plus%  is current charge     }      };

Then register in the activity's OnCreate () method

New Intentfilter (intent.action_battery_changed));

CPU Information

 Publicstring[] Getcpuinfo () {String str1= "/proc/cpuinfo"; String str2=""; String[] CpuInfo={"",""};      String[] arrayofstring; Try{FileReader fr=NewFileReader (STR1); BufferedReader Localbufferedreader=NewBufferedReader (FR, 8192); STR2=Localbufferedreader.readline (); Arrayofstring= Str2.split ("\\s+");  for(inti = 2; i < arrayofstring.length; i++) {cpuinfo[0] = Cpuinfo[0] + arrayofstring[i] + ""; } str2=Localbufferedreader.readline (); Arrayofstring= Str2.split ("\\s+"); cpuinfo[1] + = arrayofstring[2];      Localbufferedreader.close (); } Catch(IOException e) {}returnCpuInfo; }

The first row in the/proc/cpuinfo file is the CPU model, the second line is the CPU frequency, can read the file, read the data!

Version information for the system

 Publicstring[] GetVersion () {string[] version={"null", "null", "null", "NULL"}; String str1= "/proc/version";      String str2;      String[] arrayofstring; Try{FileReader Localfilereader=NewFileReader (STR1); BufferedReader Localbufferedreader=NewBufferedReader (Localfilereader,8192); STR2=Localbufferedreader.readline (); Arrayofstring= Str2.split ("\\s+"); version[0]=ARRAYOFSTRING[2];//kernelversionLocalbufferedreader.close (); } Catch(IOException e) {} version[1] = Build.VERSION.RELEASE;//Firmware versionVersion[2]=build.model;//ModelVersion[3]=build.display;//System Version    returnversion; }

Version information also includes information such as model numbers.

MAC address and boot time

 Publicstring[] Getotherinfo () {string[] other={"null", "NULL"}; Wifimanager Wifimanager=(Wifimanager) Mcontext.getsystemservice (Context.wifi_service); Wifiinfo Wifiinfo=Wifimanager.getconnectioninfo (); if(Wifiinfo.getmacaddress ()! =NULL) {other[0]=wifiinfo.getmacaddress (); } Else{other[0] = "Fail"; } other[1] =Gettimes (); returnOther ; }  PrivateString gettimes () {LongUT = Systemclock.elapsedrealtime ()/1000; if(UT = = 0) {ut= 1; }      intm = (int) ((UT/60)% 60); intH = (int) ((ut/3600)); returnH + "" + mcontext.getstring (r.string.info_times_hour) + M + "" +mcontext.getstring (R.string.info_times_minute); }

I'm the dividing line of the king of the Land Tiger.

Reference: http://gqdy365.iteye.com/blog/1066113

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.