The Silent Installation of Android is actually very simple. Today, it is very complicated to find information on the Internet for half a day, what requires system installation permissions, calling system hidden APIs, compiling in the system environment, and the same process as systemui. I don't know if they have implemented Silent Installation, But I have failed in all their ways.
Next I will talk about my silent installation implementation method. The effect of the test is the same as that of pods, and the implementation is very simple:
1. The machine supporting silent installation must be root. I don't need to talk about it more.
2. Run the PM command to install the SDK.
3. Note that the PM command does not support Chinese characters. If the path contains Chinese characters, installation may fail!
The key code is as follows:
Execrootcmdsilent ("PM install-R" + environment. getexternalstoragedirectory (). getpath () + "/xxx.apk ")
public int execRootCmdSilent(String cmd) { int result = -1; DataOutputStream dos = null; try { Process p = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(p.getOutputStream()); Log.i(TAG, cmd); dos.writeBytes(cmd + "\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); p.waitFor(); result = p.exitValue(); } catch (Exception e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
You do not need to declare any permissions in manifest.