获取系统版本内核版本信息

[img]http://dl2.iteye.com/upload/attachment/0086/7027/e3667907-67bd-3bd1-a802-5ee190e5c4f9.png[/img]

private static final String LOG_TAG = "DeviceInfoSettings";
private static final String FILENAME_PROC_VERSION = "/proc/version";
private String readLine(String filename) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filename), 256);
try {
return reader.readLine();
} finally {
reader.close();
}
}
//内核版本
private String getFormattedKernelVersion() {
String procVersionStr;
try {
procVersionStr = readLine(FILENAME_PROC_VERSION);

final String PROC_VERSION_REGEX =
"\\w+\\s+" + /* ignore: Linux */
"\\w+\\s+" + /* ignore: version */
"([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
"\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
"\\((?:[^(]*\\([^)]*\\))?[^)]*\\)\\s+" + /* ignore: (gcc ..) */
"([^\\s]+)\\s+" + /* group 3: #26 */
"(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
"(.+)"; /* group 4: date */

Pattern p = Pattern.compile(PROC_VERSION_REGEX);
Matcher m = p.matcher(procVersionStr);

if (!m.matches()) {
Log.e(LOG_TAG, "Regex did not match on /proc/version: " + procVersionStr);
return "Unavailable";
} else if (m.groupCount() < 4) {
Log.e(LOG_TAG, "Regex match on /proc/version only returned " + m.groupCount()
+ " groups");
return "Unavailable";
} else {
return (new StringBuilder(m.group(1)).append("\n").append(
m.group(2)).append(" ").append(m.group(3)).append("\n")
.append(m.group(4))).toString();
}
} catch (IOException e) {
Log.e(LOG_TAG,
"IO Exception when getting kernel version for Device Info screen",
e);

return "Unavailable";
}
}
public void showIntroduceDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("系统信息");
StringBuilder sb = new StringBuilder();
sb.append("SDK版本信息:"+Build.VERSION.SDK+"\n\n");
sb.append("Android版本信息:"+android.os.Build.VERSION.RELEASE+"\n\n");
sb.append("内核版本信息:"+getFormattedKernelVersion()+"\n\n");
builder.setMessage(sb.toString());
builder.setNegativeButton("确定", null);
builder.create().show();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值