最新公司需求写一个静默安装的功能,本人在网上找了很多代码,也都在root过的手机里面实验过。但是没有用现在贴上代码
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream dos = new DataOutputStream(process.getOutputStream());
cmd = String.valueOf(cmd);
dos.writeBytes(cmd + "\n");
dos.flush();
dos.writeBytes("exit\n");
dos.flush();
dos.close();
process.waitFor();
int result = process.exitValue();
Log.i("result", "result:"+result);
return (Integer) result;
这里result的返回值是137.不知道是什么原因。求大神指点。。。
另外还有上面Runtime.getRuntime().exec("sh");这里以前是写的su,但是代码会报一个java.io.ioException:write fail:peipe(broken pipe);
本人才学习android,所以请大家多多指教。