Android implementation of the silent installation is 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 if they really did. Silent installation No, I failed in all their ways anyway.
Let me say my 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")
1 Public intexecrootcmdsilent (String cmd) {2 intresult =-1; 3DataOutputStream dos =NULL; 4 5 Try { 6Process p = runtime.getruntime (). EXEC ("su"); 7DOS =NewDataOutputStream (P.getoutputstream ()); 8 9 log.i (TAG, CMD); TenDos.writebytes (cmd + "\ n")); One Dos.flush (); ADos.writebytes ("exit\n"); - Dos.flush (); - p.waitfor (); theresult =P.exitvalue (); -}Catch(Exception e) { - E.printstacktrace (); -}finally { + if(Dos! =NULL) { - Try { + Dos.close (); A}Catch(IOException e) { at E.printstacktrace (); - } - } - } - returnresult; -}
Do not need to declare any permissions in manifest
Original: http://blog.csdn.net/h3c4lenovo/article/details/9202323
Android silent installation/Background installation