Get basic information about Android phones

Source: Internet
Author: User

Java code
  1. /**
  2. * Get Android currently available memory size
  3. */
  4. private String getavailmemory () {//Get Android Current available memory size
  5. Activitymanager am = (activitymanager) getsystemservice (Context.activity_service);
  6. Memoryinfo mi = new Memoryinfo ();
  7. Am.getmemoryinfo (MI);
  8. //mi.availmem; available memory for the current system
  9. return Formatter.formatfilesize (Getbasecontext (), MI.AVAILMEM); //Normalize the acquired memory size
  10. }
  11. /**
  12. * Get 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 Meminfo first line, 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 () * 1024x768; Gets the total system memory, in kilobytes, multiplied by 1024 to byte
  29. Localbufferedreader.close ();
  30. } catch (IOException e) {
  31. }
  32. return Formatter.formatfilesize (Getbasecontext (), initial_memory); //byte converted to KB or MB, memory size normalized
  33. }
  34. /**
  35. * Get phone screen width high
  36. * @return
  37. */
  38. Public String Getheightandwidth () {
  39. int Width=getwindowmanager (). Getdefaultdisplay (). GetWidth ();
  40. int Heigth=getwindowmanager (). Getdefaultdisplay (). GetHeight ();
  41. String str=width+ "" +heigth+ "";
  42. return str;
  43. }
  44. /**
  45. * Get IMEI number, Iesi number, 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; //Phone model
  52. String mtyb= Android.os.Build.BRAND; //Mobile brand
  53. String Numer = Mtm.getline1number (); //Mobile phone number, some can get, some can't get
  54. LOG.I ("text", "phone IMEI number:" +imei+"mobile phone Iesi number:" +imsi+"phone model:" +mtype+"mobile phone Brand:" +mtyb+"mobile phone number +numer);
  55. }
  56. /**
  57. *. Get phone MAC Address
  58. * Only the phone turns on WiFi to get the MAC address
  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", "cell phone Macadd:" + result);
  66. return result;
  67. }
  68. /**
  69. * Mobile 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. <!--get MAC address permissions--
    2. <uses-permission android:name="Android.permission.ACCESS_WIFI_STATE"/>
    3. <!--get Mobile information right--
    4. <uses-permission android:name="Android.permission.READ_PHONE_STATE"/>

Get basic information about Android phones

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.