Android silent Installation/background installation & Root permission
silent installation is actually very simple, today on the Internet to find information for a long time are said to be very complex, what requires system installation permissions, call system hidden API, need to compile the system environment, need to systemui with the process and so on. I don't know, they did. Silent installation implementation, the pro-test effect is the same as the Pea pod, and the implementation is very simple:
1. A machine that supports silent installation must be root, and this does not require me to speak more.
2. Install with PM instructions.
3. Pay special attention to PM instruction does not support Chinese, it is said that the path of Chinese will cause installation failure!
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 (); c18/>} catch (IOException e) { e.printstacktrace ();}} } return result; }
Do not need to declare any permissions in manifest
Android silent Installation/background installation & Root permission