Android 静默安装 总结备忘

来源:互联网 发布:mac口红日本官网 编辑:程序博客网 时间:2024/04/30 06:26
先将asset下的apk拷贝到sd卡下 在执行下列代码
cmd = “pm install -r X.apk”
public static int execRootCmdSilent(String cmd) {
int result = -1;
DataOutputStream dos = null;
Process p = null;


try {
p = Runtime.getRuntime().exec("su");
dos = new DataOutputStream(p.getOutputStream());


Log.i(TAG, cmd);
dos.writeBytes(cmd + "\n");
// dos.flush();
dos.writeBytes("exit\n");
dos.flush();
p.waitFor();
result = p.exitValue();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) {
try {
dos.close();
dos = null;
} catch (IOException e) {
e.printStackTrace();
}
}
if (p != null) {
p.destroy();
p = null;
}
}
return result;
}
0 0