How Android gets mobile phone information (2)

Source: Internet
Author: User

 1.2.2.2 system information

InAndroidTo obtain system information, you can call the provided method system. getproperty (propertystr), and system information such as the user root directory (user. home) and so on can be obtained through this method, the implementation code is as follows:

Java code:

Public static stringbuffer buffer = NULL;
Private Static string initproperty (string description, string propertystr ){
If (buffer = NULL ){
Buffer = new stringbuffer ();
}
Buffer. append (description). append (":");
Buffer. append (system. getproperty (propertystr). append ("");
Return buffer. tostring ();
}

Private Static string getsystemproperty (){
Buffer = new stringbuffer ();
Initproperty ("Java. Vendor. url", "Java. Vendor. url ");
Initproperty ("Java. Class. Path", "Java. Class. Path ");
Return buffer. tostring ();
}

 

The above code mainly obtains the specified system information by calling the system. getproperty method provided by the system, and combines the information into a string for return.

  1.2.2.3 carrier Information

The carrier information includes the IMEI and mobile phone number.AndroidProvides the operator management class (telephonymanager). You can use telephonymanager to obtain carrier-related information. The key code for implementation is as follows:

Java code:

Public static string fetch_tel_status (context CX ){
String result = NULL;
Telephonymanager TM = (telephonymanager) Cx. getsystemservice (context. telephony_service );
String STR = "";
STR + = "DeviceID (IMEI) =" + TM. getdeviceid () + "";
STR + = "devicesoftwareversion =" + TM. getdevicesoftwareversion () + "";
// Todo: Do something...
Int MCC = Cx. getresources (). getconfiguration (). MCC;
Int MNC = Cx. getresources (). getconfiguration (). MNC;
STR + = "imsi MCC (mobile country code):" + String. valueof (MCC) + "";
STR + = "imsi MNC (mobile network code):" + String. valueof (MNC) + "";
Result = STR;
Return result;
} In the above Code, first call the system's getsystemservice (context. the telephony_service method obtains a telephonymanager object TM, calls its method getdeviceid () to obtain DeviceID information, and CALLS getdevicesoftware version () to obtain the software version information of the device.

  1.2.3 view hardware information
1.2.3.1 obtain CPU Information

You can obtain CPU information from/proc/cpuinfo on the mobile phone device, call cmdeexecute to execute the cat command of the system, and obtain the content of/proc/cpuinfo, which displays the CPU information, the implementation code is as follows:

Java code:

 

In the above Code, first call the system's getsystemservice (context. the telephony_service method obtains a telephonymanager object TM, calls its method getdeviceid () to obtain DeviceID information, and CALLS getdevicesoftware version () to obtain the software version information of the device.

  1.2.3 view hardware information
1.2.3.1 obtain CPU Information

You can obtain CPU information from/proc/cpuinfo on the mobile phone device, call cmdeexecute to execute the cat command of the system, and obtain the content of/proc/cpuinfo, which displays the CPU information, the implementation code is as follows:

Java code:

Public static string fetch_cpu_info (){
String result = NULL;
Cmdexecute cmdexe = new cmdexecute ();
Try {
String [] ARGs = {"/system/bin/cat", "/proc/cpuinfo "};
Result = cmdexe. Run (ARGs, "/system/bin /");
Log. I ("result", "result =" + result );
} Catch (ioexception ex ){
Ex. printstacktrace ();
}
Return result;
}

The above Code uses cmdexecute to call the "/system/bin/cat" command in the system to view the content in "/proc/cpuinfo" to obtain CPU information.

 

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.