Android系统是基于Linux的,各个Android版本对应的Linux版本不尽相同,我们这里不去追究各个Android对应的Linux版本是什么,而是通过工具或者使用代码的方法去获取我们使用的Android源码或者我们的Android手机目前使用的Linux版本。

 

首先,使用adb工具我们能够很快获取Android手机(Android模拟器)的Linux内核版本。

用adb工具连接模拟器,查看内核版本信息,看看模拟器上跑的内核是不是我们刚才编译出来的内核:

     USER-NAME@MACHINE-NAME:~/Android$ adb shell

      这时候如果是第一次运行 adb shell命令,会看到以下输出,不用管它,再运行一次adb shell命令就可以了。

     切换到proc目录:



[html]  view plain  copy

1. root@android:/ # cd proc  
2. root@android:/proc # cat version  
3. Linux version 3.0.8 (user@machine) (gcc version 4.4.3 (GCC) ) #1 SMP PREEMP  
4. T Mon Mar 3 11:32:08 CST 2014



 机器名user@machine;日期Mon Mar 3 11:32:08 CST 2014;Linux内核版本为Linux ersion 3.0.8

         其次,在一些应用中我们有可能需要获取Linux内核的版本信息,基于adb命令行的的获取方式,我们知道Linux版本信息是通过Linux命令获取的,那么该过程我们当然可以通过代码来实现它。





[java]  view plain  copy

1. /***
2.      * 获取Android Linux内核版本信息
3.      */  
4. public void getLinuxKernalInfo() {  
5. null;  
6. null;  
7. try {  
8. "cat /proc/version");  
9. catch (IOException e) {  
10. // TODO Auto-generated catch block  
11.             e.printStackTrace();  
12.         }  
13.   
14. // get the output line  
15.         InputStream outs = process.getInputStream();  
16. new InputStreamReader(outs);  
17. new BufferedReader(isrout, 8 * 1024);  
18.   
19. "";  
20.         String line;  
21. // get the whole standard output string  
22. try {  
23. while ((line = brout.readLine()) != null) {  
24.                 result += line;  
25. // result += "\n";  
26.             }  
27. catch (IOException e) {  
28. // TODO Auto-generated catch block  
29.             e.printStackTrace();  
30.         }  
31.   
32. if (result != "") {  
33. "version ";  
34. int index = result.indexOf(Keyword);  
35. "----"+result);  
36.             line = result.substring(index + Keyword.length());  
37. " ");  
38. // tv01.setText(line.substring(0,index));  
39. 0, index);  
40.   
41. "----Linux Kernal is : " + mLinuxKernal);  
42.         }  
43.     }



除了上面的方法以外还可以通过给processbuilder传入一个String数组,String数组有两个String,前一个代表liunx系统的命令,后面一个代表要执行该命令的文件然后就是获得该命令执行后所返回的字符串信息以流的形式再传回来得到 result。

这个方法和上面的大同小异,只是使用的方法略微不同。

具体如下:





[java]  view plain  copy



1. public String getLinuxKernalInfoEx() {  
2. "";  
3.         String line;  
4. new String[] { "/system/bin/cat", "/proc/version" };  
5. "/system/bin/";  
6. try {  
7. new ProcessBuilder(cmd);  
8. new File(workdirectory));  
9. true);  
10.             Process process = bulider.start();  
11.             InputStream in = process.getInputStream();            
12. new InputStreamReader(in);  
13. new BufferedReader(isrout, 8 * 1024);  
14.   
15. while ((line = brout.readLine()) != null) {  
16.                 result += line;  
17. // result += "\n";  
18.             }  
19.             in.close();           
20.   
21. catch (Exception e) {  
22.             e.printStackTrace();  
23.         }  
24. "----Linux Kernal is :"+result);  
25. return result;  
26.     }


Android系统是基于Linux的,各个Android版本对应的Linux版本不尽相同,我们这里不去追究各个Android对应的Linux版本是什么,而是通过工具或者使用代码的方法去获取我们使用的Android源码或者我们的Android手机目前使用的Linux版本。

 

首先,使用adb工具我们能够很快获取Android手机(Android模拟器)的Linux内核版本。

用adb工具连接模拟器,查看内核版本信息,看看模拟器上跑的内核是不是我们刚才编译出来的内核:

     USER-NAME@MACHINE-NAME:~/Android$ adb shell

      这时候如果是第一次运行 adb shell命令,会看到以下输出,不用管它,再运行一次adb shell命令就可以了。

     切换到proc目录:



[html]  view plain  copy



1. root@android:/ # cd proc  
2. root@android:/proc # cat version  
3. Linux version 3.0.8 (user@machine) (gcc version 4.4.3 (GCC) ) #1 SMP PREEMP  
4. T Mon Mar 3 11:32:08 CST 2014



 机器名user@machine;日期Mon Mar 3 11:32:08 CST 2014;Linux内核版本为Linux ersion 3.0.8

         其次,在一些应用中我们有可能需要获取Linux内核的版本信息,基于adb命令行的的获取方式,我们知道Linux版本信息是通过Linux命令获取的,那么该过程我们当然可以通过代码来实现它。





[java]  view plain  copy



1. /***
2.      * 获取Android Linux内核版本信息
3.      */  
4. public void getLinuxKernalInfo() {  
5. null;  
6. null;  
7. try {  
8. "cat /proc/version");  
9. catch (IOException e) {  
10. // TODO Auto-generated catch block  
11.             e.printStackTrace();  
12.         }  
13.   
14. // get the output line  
15.         InputStream outs = process.getInputStream();  
16. new InputStreamReader(outs);  
17. new BufferedReader(isrout, 8 * 1024);  
18.   
19. "";  
20.         String line;  
21. // get the whole standard output string  
22. try {  
23. while ((line = brout.readLine()) != null) {  
24.                 result += line;  
25. // result += "\n";  
26.             }  
27. catch (IOException e) {  
28. // TODO Auto-generated catch block  
29.             e.printStackTrace();  
30.         }  
31.   
32. if (result != "") {  
33. "version ";  
34. int index = result.indexOf(Keyword);  
35. "----"+result);  
36.             line = result.substring(index + Keyword.length());  
37. " ");  
38. // tv01.setText(line.substring(0,index));  
39. 0, index);  
40.   
41. "----Linux Kernal is : " + mLinuxKernal);  
42.         }  
43.     }



除了上面的方法以外还可以通过给processbuilder传入一个String数组,String数组有两个String,前一个代表liunx系统的命令,后面一个代表要执行该命令的文件然后就是获得该命令执行后所返回的字符串信息以流的形式再传回来得到 result。

这个方法和上面的大同小异,只是使用的方法略微不同。

具体如下:





[java]  view plain  copy


1. public String getLinuxKernalInfoEx() {  
2. "";  
3.         String line;  
4. new String[] { "/system/bin/cat", "/proc/version" };  
5. "/system/bin/";  
6. try {  
7. new ProcessBuilder(cmd);  
8. new File(workdirectory));  
9. true);  
10.             Process process = bulider.start();  
11.             InputStream in = process.getInputStream();            
12. new InputStreamReader(in);  
13. new BufferedReader(isrout, 8 * 1024);  
14.   
15. while ((line = brout.readLine()) != null) {  
16.                 result += line;  
17. // result += "\n";  
18.             }  
19.             in.close();           
20.   
21. catch (Exception e) {  
22.             e.printStackTrace();  
23.         }  
24. "----Linux Kernal is :"+result);  
25. return result;  
26.     }