我試圖在沒有任何提示的情況下默默安裝apk。java.io.IOException:運行exec()時出錯。命令:Working Directory:null環境:null
這是使用adb命令安裝apk文件的代碼。
public void InstallAPK(String filename){
File file = new File(filename);
if(file.exists()){
try {
String command;
command = "adb install -r " + filename;
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
但是當我運行這段代碼時,出現以下錯誤。
java.io.IOException:運行exec()時發生錯誤。命令:[蘇,-c,亞行安裝-r /storage/emulated/0/Download/sampleapp.apk]工作指南:空環境:空
我已經給這些權限。
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
請有人可以幫我解決這個錯誤。
你能找到解決方案嗎?如果是這樣,請讓我知道。 – Jaydev