[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();
}