I am trying to install the application programatically without prompt. Means, installing the app without showing the pop-up where user has to press install option. I followed THIS answer. But whenever I am running the code, it is throwing the error
java.io.IOException: Error running exec(). Command: [su, -c, adb install -r /storage/emulated/0/update.apk] Working Directory: null Environment: null
Caused by: java.io.IOException: Permission denied at java.lang.ProcessManager.exec(Native Method) at java.lang.ProcessManager.exec(ProcessManager.java:209)
It says Permission denied, but doesn't tell which permission. The apk is in the storage of the device and I have provided following permissions in the manifest.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Following is the code that I use for installing the 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();
}
}
}
And I call this function as:
InstallAPK(Environment.getExternalStorageDirectory().getAbsolutePath()+"/update.apk");
Can someone please help me with the permission that I am missing.