Android-system information (memory, cpu, SD card, power, Version)

Source: Internet
Author: User

Android-system information (memory, cpu, SD card, power, Version)
The total memory size of memory (ram) android is stored in the system's/proc/meminfo file. You can read this file to obtain this information: copy the code public void getTotalMemory () {String str1 = "/proc/meminfo"; String str2 = ""; try {FileReader fr = new FileReader (str1); BufferedReader localBufferedReader = new BufferedReader (fr, 8192 ); while (str2 = localBufferedReader. readLine ())! = Null) {Log. I (TAG, "---" + str2) ;}} catch (IOException e) {}} copy the code run information as follows: Copy code 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- MemTotal: 204876 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- MemFree: 4596 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- Buffers: 16020 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- Cached: 82508 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- SwapCa Ched: 64 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- Active: 137104 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- Inactive: 41056 kB 05-30 08:05:14. 807: INFO/-SystemInfo-(1519): --- SwapTotal: 65528 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- SwapFree: 65368 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- Dirty: 88 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- Writeback: 0 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- AnonPages: 79672 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- Mapped: 38296 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- Slab: 5768 kB 05-30 08:05:14. 817: INFO/-SystemInfo-(1519): --- SReclaimable: 1856 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- SUnreclaim: 3912 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- PageTables: 81 84 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- NFS_Unstable: 0 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- Bounce: 0 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- CommitLimit: 167964 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- Committed_AS: 11771920 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- VmallocTotal: 761856 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- V MallocUsed: 83656 kB 05-30 08:05:14. 827: INFO/-SystemInfo-(1519): --- VmallocChunk: 674820 kB copy the code. The first line is the total memory size (that is, the size of the ram that users can use )! To obtain the size of the remaining memory (ram), copy the code public long getAvailMemory () {ActivityManager am = (ActivityManager) mContext. getSystemService (Context. ACTIVITY_SERVICE); ActivityManager. memoryInfo mi = new ActivityManager. memoryInfo (); am. getMemoryInfo (mi); return mi. availMem;} copy Code Rom size copy code public long [] getRomMemroy () {long [] romInfo = new long [2]; // Total rom memory romInfo [0] = getTotalInternalMemorySize (); // Availa Ble rom memory File path = Environment. getDataDirectory (); StatFs stat = new StatFs (path. getPath (); long blockSize = stat. getBlockSize (); long availableBlocks = stat. getAvailableBlocks (); romInfo [1] = blockSize * availableBlocks; getVersion (); return romInfo;} public long getTotalInternalMemorySize () {File path = Environment. getDataDirectory (); StatFs stat = new StatFs (path. getPath (); long blo CkSize = stat. getBlockSize (); long totalBlocks = stat. getBlockCount (); return totalBlocks * blockSize;} copy the code to pay attention to the type. Otherwise, overflow occurs after multiplication. The available internal storage size cannot be obtained through getRootDirectory ();. Many of the previously uploaded files were obtained using getRootDirectory (). After testing, I found that the obtained value is incorrect. It must be obtained according to getDataDirectory. SDcard size copy code public long [] getSDCardMemory () {long [] sdCardInfo = new long [2]; String state = Environment. getExternalStorageState (); if (Environment. MEDIA_MOUNTED.equals (state) {File sdcardDir = Environment. getExternalStorageDirectory (); StatFs sf = new StatFs (sdcardDir. getPath (); long bSize = sf. getBlockSize (); long bCount = sf. getBlockCount (); long availBlocks = sf. getAvailableBlocks (); sdCard Info [0] = bSize * bCount; // total size sdCardInfo [1] = bSize * availBlocks; // available size} return sdCardInfo;} copy the code note type, otherwise, overflow occurs after multiplication. Battery power replication code private BroadcastReceiver batteryReceiver = new BroadcastReceiver () {@ Override public void onReceive (Context context, Intent intent) {int level = intent. getIntExtra ("level", 0); // level plus % indicates the current power}; copy the code and register registerReceiver (batteryReceiver, new IntentFilter (Intent. ACTION_BATTERY_CHANGED); CPU information copy code public String [] getCpuInfo () {String str1 = "/proc/cpuinfo"; Strin G str2 = ""; String [] cpuInfo = {"", ""}; String [] arrayOfString; try {FileReader fr = new FileReader (str1 ); bufferedReader localBufferedReader = new BufferedReader (fr, 8192); str2 = localBufferedReader. readLine (); arrayOfString = str2.split ("\ s +"); for (int I = 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) {} return cpuInfo;} copy the first line of the Code/proc/cpuinfo file to the CPU model, and the second line to the CPU frequency, you can read the data by reading the file! System version Information copy code public String [] getVersion () {String [] version = {"null", "null "}; string str1 = "/proc/version"; String str2; String [] delimiter; try {FileReader localFileReader = new FileReader (str1); BufferedReader localBufferedReader = new BufferedReader (localFileReader, 8192 ); str2 = localBufferedReader. readLine (); arrayOfString = str2.split ("\ s +"); version [0] = arrayOfString [2];/ /KernelVersion localBufferedReader. close ();} catch (IOException e) {} version [1] = Build. VERSION. RELEASE; // firmware version [2] = Build. MODEL; // model version [3] = Build. DISPLAY; // system version return version;} copy the code version information, including the model and other information. Public String [] 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 (); return other ;}private String getTimes () {long ut = SystemClock. elapsedRealtime ()/1000; if (ut = 0) {ut = 1;} int m = (int) (ut/60) % 60 ); int h = (int) (ut/3600); return h + "" + mContext. getString (R.string.info _ times_hour) + m + "+ mContext. getString (R.string.info _ times_minute );}

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.