Java tutorial
//package com.java2s; import android.os.Build; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String getModVersion() { String modVersion = getSystemProperty(); if (modVersion == null || modVersion.length() == 0) { modVersion = getCustomROM(); } return (modVersion == null || modVersion.length() == 0 ? "Unknown" : modVersion); } public static String getSystemProperty() { String line = null; BufferedReader reader = null; try { Process p = Runtime.getRuntime().exec("getprop ro.miui.ui.version.name"); reader = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = reader.readLine(); return line; } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } return "UNKNOWN"; } public static String getCustomROM() { String line; BufferedReader input = null; StringBuilder sb = new StringBuilder(); String version = Build.VERSION.RELEASE; try { Process process = Runtime.getRuntime().exec("getprop ro.build.description"); input = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"), 1024); line = input.readLine(); if (line == null || line.length() == 0) { return null; } String[] s = line.split("\\s"); for (int i = 0; i < s.length; i++) { if (!s[i].equals(version) && !s[i].contains("key")) { sb.append(s[i] + " "); } } input.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } finally { if (input != null) { try { input.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return sb.toString(); } }