//静默安装,仅供参考
private static int cmdInstallApk(String apkPath) {
String cmd = ("pm install -r " + apkPath);
DataOutputStream dataOutputStream = null;
try {
//手机必须root
Process process = Runtime.getRuntime().exec("su");// (这里执行是系统已经开放了root权限,而不是说通过执行这句来获得root权限)
dataOutputStream = new DataOutputStream(
(OutputStream) process.getOutputStream());
// 部分手机Root之后Library path 丢失,导入path可解决该问题
dataOutputStream.writeBytes((String) "export LD_LIBRARY_PATH=/vendor/lib:/system/lib\n");
cmd = String.valueOf(cmd);
dataOutputStream.writeBytes((String) (cmd + "\n"));
dataOutputStream.flush();
dataOutputStream.writeBytes("am start -n " + “包名” + "/" +“包名” + ".MainActivity" + " \n");
dataOutputStream.flush();
process.waitFor();