private static final String CHARSET_NAME = "UTF-8"; String cmd = "pm clear com.android.browser"; ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true).command("su"); Process p = pb.start(); // We must handle the result stream in another Thread first StreamReader stdoutReader = new StreamReader(p.getInputStream(), CHARSET_NAME); stdoutReader.start(); out = p.getOutputStream(); out.write((cmd + "\n").getBytes(CHARSET_NAME)); out.write(("exit" + "\n").getBytes(CHARSET_NAME)); out.flush(); p.waitFor(); String result = stdoutReader.getResult();
public static final String readRegistry(String location, String key){ try { // Run reg query, then read output with StreamReader (internal class) Process process = Runtime.getRuntime().exec("reg query " + '"'+ location + "\" /v " + key); StreamReader reader = new StreamReader(process.getInputStream()); reader.start(); process.waitFor(); reader.join(); String output = reader.getResult(); // Output has the following format: // \n<Version information>\n\n<key>\t<registry type>\t<value> if( ! output.contains("\t")){ return null; } // Parse out the value String[] parsed = output.split("\t"); return parsed[parsed.length-1]; } catch (Exception e) { return null; } }