Android obtains mobile phone information

Source: Internet
Author: User
  1. /**
  2. * Get mobile phone information
  3. */
  4. Public void getphoneinfo ()
  5. {
  6. Telephonymanager TM = (telephonymanager) This. getsystemservice (telephony_service );
  7. String mtyb = Android. OS. Build. Brand; // mobile phone brand
  8. String mtype = Android. OS. Build. Model; // Mobile Phone Model
  9. String IMEI = TM. getdeviceid ();
  10. String imsi = TM. getsubscriberid ();
  11. String numer = TM. getline1number (); // mobile phone number
  12. String servicename = TM. getsimoperatorname (); // Carrier
  13. Tvphoneinfo. settext ("brand:" + mtyb + "\ n" + "model:" + mtype + "\ n" + "version: Android" + android. OS. build. version. release + "\ n" + "IMEI:" + IMEI
  14. + "\ N" + "imsi:" + imsi + "\ n" + "mobile phone number:" + numer + "\ n" + "carrier: "+ servicename +" \ n ");
  15. }

[Java]
View plaincopyprint?
  1. /**
  2. * Get the phone memory size
  3. *
  4. * @ Return
  5. */
  6. Private string gettotalmemory ()
  7. {
  8. String str1 = "/proc/meminfo"; // system memory information file
  9. String str2;
  10. String [] arrayofstring;
  11. Long initial_memory = 0;
  12. Try
  13. {
  14. Filereader localfilereader = new filereader (str1 );
  15. Bufferedreader localbufferedreader = new bufferedreader (localfilereader, 8192 );
  16. Str2 = localbufferedreader. Readline (); // read the first line of meminfo, total system memory size
  17. Arrayofstring = str2.split ("\ s + ");
  18. For (string num: arrayofstring)
  19. {
  20. Log. I (str2, num + "\ t ");
  21. }
  22. Initial_memory = integer. valueof (arrayofstring [1]). intvalue () * 1024; // obtain the total system memory, measured in KB, multiplied by 1024 to byte
  23. Localbufferedreader. Close ();
  24. }
  25. Catch (ioexception E)
  26. {
  27. }
  28. Return formatter. formatfilesize (getbasecontext (), initial_memory); // convert byte to kb or MB, and normalize the memory size.
  29. }

[Java]
View plaincopyprint?

  1. /**
  2. * Get the current available memory size
  3. *
  4. * @ Return
  5. */
  6. Private string getavailmemory ()
  7. {
  8. Activitymanager AM = (activitymanager) getsystemservice (context. activity_service );
  9. Memoryinfo MI = new memoryinfo ();
  10. Am. getmemoryinfo (MI );
  11. Return formatter. formatfilesize (getbasecontext (), mi. availmem );
  12. }
[Java]
View plaincopyprint?
  1. /**
  2. * Obtain the CPU information of the mobile phone.
  3. *
  4. * @ Return
  5. */
  6. Public String [] getcpuinfo ()
  7. {
  8. String str1 = "/proc/cpuinfo ";
  9. String str2 = "";
  10. String [] cpuinfo = {"",""};
  11. String [] arrayofstring;
  12. Try
  13. {
  14. Filereader Fr = new filereader (str1 );
  15. Bufferedreader localbufferedreader = new bufferedreader (FR, 8192 );
  16. Str2 = localbufferedreader. Readline ();
  17. Arrayofstring = str2.split ("\ s + ");
  18. For (INT I = 2; I <arrayofstring. length; I ++)
  19. {
  20. Cpuinfo [0] = cpuinfo [0] + arrayofstring [I] + "";
  21. }
  22. Str2 = localbufferedreader. Readline ();
  23. Arrayofstring = str2.split ("\ s + ");
  24. Cpuinfo [1] + = arrayofstring [2];
  25. Localbufferedreader. Close ();
  26. }
  27. Catch (ioexception E)
  28. {
  29. }
  30. Tvhardwareinfo. append ("CPU model" + cpuinfo [0] + "\ n" + "CPU frequency:" + cpuinfo [1] + "\ n ");
  31. Return cpuinfo;
  32. }
[Java]
View plaincopyprint?
  1. /**
  2. * Obtain the number of CPU Cores
  3. *
  4. * @ Return
  5. */
  6. Private int getnumcores ()
  7. {
  8. // Private class to display only CPU devices in the Directory Listing
  9. Class cpufilter implements filefilter
  10. {
  11. @ Override
  12. Public Boolean accept (File pathname)
  13. {
  14. // Check if filename is "CPU", followed by a single digit number
  15. If (pattern. Matches ("CPU [0-9]", pathname. getname ()))
  16. {
  17. Return true;
  18. }
  19. Return false;
  20. }
  21. }
  22. Try
  23. {
  24. // Get directory containing CPU info
  25. File dir = new file ("/sys/devices/system/CPU /");
  26. // Filter to only list the devices we care about
  27. File [] files = dir. listfiles (New cpufilter ());
  28. // Return the number of cores (virtual CPU devices)
  29. Return files. length;
  30. }
  31. Catch (exception E)
  32. {
  33. E. printstacktrace ();
  34. // Default to return 1 core
  35. Return 1;
  36. }
  37. }

Source: http://blog.csdn.net/vestigge/article/details/8691894

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.