获取系统版本内核版本信息
16lz
2021-01-26
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(); }
更多相关文章
- Android(安卓)获取当前连接的WiFi信息
- Android-Android(安卓)API 版本判断
- 数据库版本升级降级
- Android(安卓)SDK 版本对应版本号
- Android系统的版本号与API的对应表
- Android电源信息
- android实现解析webservices
- android 获取rom名称和版本号
- Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskIn