我有一个必须使用 pm install 的 android 程序,它是一个企业应用程序,我想运行 pm install 为我们的客户静默更新应用程序
我有一个方法可以运行 pm install 但什么也没发生,我不明白为什么?有人可以帮助我吗?
private void installproperlyApp(){
Process process = null;
try{
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
System.out.println("DANS LE INSTALL COMMAND");
os.writeBytes("pm install -r /sdcard/telegestion.apk"+"\n");
os.writeBytes("exit\n");
os.flush();
os.close();
String line ="";
//on récupère l'inputStream sinon on a un deadLock pour le process
BufferedReader inputProcess = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = inputProcess.readLine()) != null) {
System.out.println(line);
}
//on récupère l'errorStream sinon on a un deadLock pour le process
BufferedReader errorProcess = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = errorProcess.readLine()) != null) {
System.out.println(line);
}
//process.waitFor();
} catch (IOException e) {
System.out.println(e.toString());
} finally {
if (process != null)
process.destroy();
}
}