Android system information retrieval: Linux kernel Version Information Retrieval
The Android system is based on Linux, and the Linux versions of each Android version are different. We will not investigate the Linux versions of each Android, instead, we use tools or code to obtain the Android source code we use or the Linux version currently used by our Android mobile phone.
First, we can use the adb tool to quickly obtain the Linux kernel version of the Android mobile phone (Android simulator.
Use the adb tool to connect to the simulator, view the kernel version information, and see if the kernel running on the simulator is the kernel we just compiled:
USER-NAME @ MACHINE-NAME :~ /Android $ adb shell
If this is the first time you run the adb shell command, you will see the following output. You can run the adb shell command again without having to worry about it.
Switch to the proc directory:
root@android:/ # cd procroot@android:/proc # cat versionLinux version 3.0.8 (user@machine) (gcc version 4.4.3 (GCC) ) #1 SMP PREEMPT Mon Mar 3 11:32:08 CST 2014
Machine name user @ machine; date: Mon Mar 3 11:32:08 CST 2014; Linux kernel version: Linux ersion 3.0.8
Secondly, in some applications, we may need to obtain the Linux kernel version information. Based on the adb command line acquisition method, we know that the Linux version information is obtained through the Linux Command, we can certainly implement this process through code.
/***** Get Android Linux kernel version information */public void getLinuxKernalInfo () {Process process = null; String mLinuxKernal = null; try {process = runtime.getruntime(cmd.exe c ("cat/proc/version");} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace ();} // get the output lineInputStream outs = process. getInputStream (); InputStreamReader isrout = new InputStreamReader (outs); BufferedReader brout = New BufferedReader (isrout, 8*1024); String result = ""; String line; // get the whole standard output stringtry {while (line = brout. readLine ())! = Null) {result + = line; // result + = "\ n" ;}} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace ();} if (result! = "") {String Keyword = "version"; int index = result. indexOf (Keyword); Log. v (TAG, "----" + result); line = result. substring (index + Keyword. length (); index = line. indexOf (""); // tv01.setText (line. substring (0, index); mLinuxKernal = line. substring (0, index); Log. d (TAG, "---- Linux Kernal is:" + mLinuxKernal );}}
In addition to the above method, you can also pass a String array to processbuilder. The String array has two strings, and the previous one represents the liunx system command, the following file indicates that the command is to be executed, and then the string information returned after the command is executed is passed back as a stream to get the result.
This method is similar to the above method, but the method used is slightly different.
The details are as follows:
public String getLinuxKernalInfoEx() {String result = "";String line;String[] cmd = new String[] { "/system/bin/cat", "/proc/version" };String workdirectory = "/system/bin/";try {ProcessBuilder bulider = new ProcessBuilder(cmd);bulider.directory(new File(workdirectory));bulider.redirectErrorStream(true);Process process = bulider.start();InputStream in = process.getInputStream();InputStreamReader isrout = new InputStreamReader(in);BufferedReader brout = new BufferedReader(isrout, 8 * 1024);while ((line = brout.readLine()) != null) {result += line;// result += "\n";}in.close();} catch (Exception e) {e.printStackTrace();}Log.i(TAG,"----Linux Kernal is :"+result);return result;}
It can be used as appropriate in development.