Many of the information on the Android system can be obtained through the/proc directory, such as
Cat/proc/cpuinfo Getting CPU Information
Cat/proc/meminfo Getting memory information
This information is saved in text format, can be read through IO stream, relatively simple, here to consider that some content is not saved as text, disk information
We implement a Linux command parser through code to obtain the information
The instruction parser is as follows:
public class Cmdexecutor {/** * Execute command * @param cmd command parameter * @param workdir current directory (that is, execute instruction pwd See directory) * @return */public Synchronized string run (string[] cmd, string workdir) {string result = ""; InputStream is = null;try {Processbuilder Builder = new Processbuilder (cmd); Textutils.isempty (Workdir)) {builder.directory (new File (Workdir)); Set the execution instruction directory Builder.redirecterrorstream (); Process process = Builder.start (); Execute instruction is = Process.getinputstream (); byte[] buf = new Byte[1024];int len = 0;while (len = Is.read (BUF))! =-1) {result + = N EW String (buf, 0, Len);}}} catch (Exception e) {return null;} Finally{if (is! = null) {try {is.close ();} catch (IOException e) {e.printstacktrace ();}}} return result;}}
To obtain the mobile phone Information tool class:
public class Getphoneinfoutil {//Get kernel version, GCC version, etc. public String fetch_version_info () {string result = NULL; Cmdexecutor CmdExe = new Cmdexecutor (); string[] args = {"/system/bin/cat", "/proc/version"}; "/system/bin/cat" instruction absolute path result = Cmdexe.run (args, "system/bin/"); Specified instruction execution directory, above absolute path writable relative path "cat" return result; Get CPU Information public string Fetch_cpu_info () {string result = NULL; Cmdexecutor CmdExe = new Cmdexecutor (); string[] args = {"/system/bin/cat", "/proc/cpuinfo"};result = Cmdexe.run (args, "/system/bin/"); return result; To add a permission: android.permission.read_phone_state//operator Information public String Fetch_tel_status (context context) {string result = Null Telephonymanager TM = (Telephonymanager) context.getsystemservice (Context.telephony_service); String str = ""; str + = "DeviceId (IMEI) =" + Tm.getdeviceid () + "\ n"; str + = "Devicesoftwareversion =" + Tm.getdevicesoft Wareversion () + "\ n"; int mcc = Context.getresources (). GetConfiguration (). Mcc;int MNC = Context.getresources (). GetConfiguration (). mnc;str+ = "IMSI MCC (Mobile Country Code):" + string.valueof (MCC) + "\ n"; str + = "IMSI MNC (Mobile Network Code):" + String.valu EOf (MNC) + "\ n"; result = Str;return result;} private static StringBuffer buffer = Null;public static string Initproperty (string description, String propertystr) {if (b Uffer = = null) {buffer = new StringBuffer ();} Buffer.append (description). Append (": \ T"); Buffer.append (System.getproperty (PROPERTYSTR)). Append ("\ n"); return Buffer.tostring ();} public static String Getsystemproperty () {buffer = new StringBuffer (); Initproperty ("Java.vendor.url", "Java.vendor.url Initproperty ("Java.class.path", "Java.class.path"), Initproperty ("Os.name", "Os.name"); Initproperty (" Os.version "," os.version "); Initproperty (" User.home "," User.home "); return buffer.tostring ();} Get Network Information public static string Fetch_netcfg_info () {string result = NULL; Cmdexecutor CmdExe = new Cmdexecutor (); string[] args = {"/system/bin/netcfg"};result = Cmdexe.run (args, "/system/bin/"); return result;} Disk Information public StatiC String Fetch_disk_info () {string result = NULL; Cmdexecutor CmdExe = new Cmdexecutor (); string[] args = {"/SYSTEM/BIN/DF"};result = Cmdexe.run (args, "/system/bin/"); return result;} Gets the display frequency information public static String Getdisplaymetrics (context context) {string str = "";D isplaymetrics dm = new Displaymetrics ( );d m = context.getresources (). Getdisplaymetrics ();//The line above is equivalent to the following two lines//windowmanager wm = (WindowManager) getsystemservice (Window_service);//wm.getdefaultdisplay (). Getmetrics (DM); int screenwidth = Dm.widthpixels;int ScreenHeight = Dm.heightpixels;float density = dm.density;float xdpi = dm.xdpi;float ydpi = dm.ydpi;str + = "The absolute width:" + strin G.valueof (screenwidth) + "Pixels \ n"; str + = "The absolute heightin:" + string.valueof (screenheight) + "Pixels \ n"; str + = "The logical density of the display:" + string.valueof (density) + "\ n"; str + = "X dimension:" + string.valueof (xdpi) + " pixels per inch \ n "; str + =" Y dimension: "+ string.valueof (ydpi) +" pixels per inch \ n "; return str;}
for System.getproperty (), refer tothe System.getproperty () method can get the value
Android Get mobile Info