Android靜默安裝的方法,靜默安裝就是繞過安裝程序時(shí)的提示窗口,直接在后臺(tái)安裝。
注意:靜默安裝的前提是設(shè)備有ROOT權(quán)限。
代碼如下:
/** * 靜默安裝 * @param file * @return */ public boolean slientInstall(File file) { boolean result = false; Process process = null; OutputStream out = null; 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(); // 關(guān)閉流操作 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(); } return result; } 注意代碼中pm install -r 前面的LD_LIBRARY_PATH=/vendor/lib:/system/lib,在4.0版本以上必須加上,不然會(huì)無法安裝。
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注