Obtain basic information about android phones and basic information about android phones.

Source: Internet
Author: User

Obtain basic information about android phones and basic information about android phones.
Java code

  1. /**
  2. * Get the current available memory size of android
  3. */
  4. Private String getAvailMemory () {// gets the current available memory size of android
  5. ActivityManager am = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE );
  6. MemoryInfo mi = new MemoryInfo ();
  7. Am. getMemoryInfo (mi );
  8. // Mi. availMem; available memory of the current system
  9. Return Formatter. formatFileSize (getBaseContext (), mi. availMem); // normalize the obtained memory size
  10. }
  11. /**
  12. * Obtain the total system memory.
  13. */
  14. Private String getTotalMemory (){
  15. String str1 = "/proc/meminfo"; // system memory information file
  16. String str2;
  17. String [] arrayOfString;
  18. Long initial_memory = 0;
  19. Try {
  20. FileReader localFileReader = new FileReader (str1 );
  21. BufferedReader localBufferedReader = new BufferedReader (
  22. LocalFileReader, 8192 );
  23. Str2 = localBufferedReader. readLine (); // read the first line of meminfo, total system memory size
  24. ArrayOfString = str2.split ("\ s + ");
  25. For (String num: arrayOfString ){
  26. Log. I (str2, num + "\ t ");
  27. }
  28. Initial_memory = Integer. valueOf (arrayOfString [1]). intValue () * 1024; // obtain the total system memory, measured in KB, multiplied by 1024 to Byte
  29. LocalBufferedReader. close ();
  30. } Catch (IOException e ){
  31. }
  32. Return Formatter. formatFileSize (getBaseContext (), initial_memory); // convert Byte to KB or MB, and normalize the memory size.
  33. }
  34. /**
  35. * Screen width and height
  36. * @ Return
  37. */
  38. Public String getHeightAndWidth (){
  39. Int width = getWindowManager (). getDefaultDisplay (). getWidth ();
  40. Int heigth = getWindowManager (). getdefadisplay display (). getHeight ();
  41. String str = width + "" + heigth + "";
  42. Return str;
  43. }
  44. /**
  45. * Obtain the IMEI number, IESI number, and mobile phone model.
  46. */
  47. Private void getInfo (){
  48. TelephonyManager mTm = (TelephonyManager) this. getSystemService (TELEPHONY_SERVICE );
  49. String imei = mTm. getDeviceId ();
  50. String imsi = mTm. getSubscriberId ();
  51. String mtype = android. OS. Build. MODEL; // Mobile Phone MODEL
  52. String mtyb = android. OS. Build. BRAND; // mobile phone BRAND
  53. String numer = mTm. getLine1Number (); // mobile phone number, which is available or unavailable
  54. Log. I ("text", "Mobile Phone IMEI number:" + imei + "Mobile Phone IESI number:" + imsi + "Mobile Phone model:" + mtype + "mobile phone brand: "+ mtyb +" mobile phone number "+ numer );
  55. }
  56. /**
  57. *. Obtain the MAC address of the mobile phone.
  58. * The mac address can be obtained only when wifi is enabled on the mobile phone.
  59. */
  60. Private String getMacAddress (){
  61. String result = "";
  62. WifiManager wifiManager = (WifiManager) getSystemService (Context. WIFI_SERVICE );
  63. WifiInfo wifiInfo = wifiManager. getConnectionInfo ();
  64. Result = wifiInfo. getMacAddress ();
  65. Log. I ("text", "Mobile macAdd:" + result );
  66. Return result;
  67. }
  68. /**
  69. * Mobile Phone CPU Information
  70. */
  71. Private String [] getCpuInfo (){
  72. String str1 = "/proc/cpuinfo ";
  73. String str2 = "";
  74. String [] cpuInfo = {"", ""}; // 1-cpu model // 2-cpu frequency
  75. String [] arrayOfString;
  76. Try {
  77. FileReader fr = new FileReader (str1 );
  78. BufferedReader localBufferedReader = new BufferedReader (fr, 8192 );
  79. Str2 = localBufferedReader. readLine ();
  80. ArrayOfString = str2.split ("\ s + ");
  81. For (int I = 2; I <arrayOfString. length; I ++ ){
  82. CpuInfo [0] = cpuInfo [0] + arrayOfString [I] + "";
  83. }
  84. Str2 = localBufferedReader. readLine ();
  85. ArrayOfString = str2.split ("\ s + ");
  86. CpuInfo [1] + = arrayOfString [2];
  87. LocalBufferedReader. close ();
  88. } Catch (IOException e ){
  89. }
  90. Log. I ("text", "cpuinfo:" + cpuInfo [0] + "" + cpuInfo [1]);
  91. Return cpuInfo;
  92. }

 

 

Java code
  1. <! -- Obtain mac address permissions -->
  2. <Uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"/>
  3. <! -- Get mobile phone information -->
  4. <Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>

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.