在一个已经按照的程序上,静默安装另外一个程序
关键代码:
public static boolean slientInstall(String tempPath) {
File file = new File(tempPath);
boolean result = false;
Process process = null;
OutputStream out = null;
if (file.exists()) {
System.out.println(file.getPath() + "==");
try {
process = Runtime.getRuntime().exec("su");
out = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeBytes("chmod 777 " + file.getPath()
+ "\n");
dataOutputStream
.writeBytes("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install -r "
+ file.getPath());
dataOutputStream.flush();
dataOutputStream.close();
out.close();
int value = process.waitFor();
if (value == 0) {
result = true;
} else if (value == 1) {
result = false;
} else {
result = false;
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!result) {
result = true;
}
}
return result;
}
|