Boss want me to get an automatic update, to use the silent installation, online found some danale code, I take to change it, first paste it out:
Java code
- /**
- * Software Silent Installation
- * @param apkabsolutepath apk file path
- * @return Installation Result: Obtained result value <br>
- *
- * If the installation is successful, "
- * Pkg:/data/local/tmp/calculator.apk/nsuccess ",<br>
- * If it is a failure, then there is no ending "Success".
- */
- Public string Silentinstall (String apkabsolutepath) {
- string[] args = { "PM", "Install", "-R", Apkabsolutepath};
- String result = "";
- Processbuilder Processbuilder = new Processbuilder (args);
- Process process = null;
- InputStream Erris = null;
- InputStream inIs = null;
- try {
- Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();
- int read =-1;
- Process = Processbuilder.start ();
- Erris = Process.geterrorstream ();
- While (read = Erris.read ())! =-1) {
- Baos.write (read);
- }
- Baos.write ("/n". GetBytes ());
- InIs = Process.getinputstream ();
- While (read = Inis.read ())! =-1) {
- Baos.write (read);
- }
- byte[] data = Baos.tobytearray ();
- result = new String (data);
- } catch (IOException e) {
- E.printstacktrace ();
- } catch (Exception e) {
- E.printstacktrace ();
- } finally {
- try {
- if (erris! = null) {
- Erris.close ();
- }
- if (inIs! = null) {
- Inis.close ();
- }
- } catch (IOException e) {
- E.printstacktrace ();
- }
- if (process! = null) {
- Process.destroy ();
- }
- }
- return result;
- }
Don't worry, don't stop, remember to add permission:
Java code
- <!--The following are the permissions required to install the APK silently--
- <uses-permission android:name="Android.permission.INSTALL_PACKAGES"/>
- <uses-permission android:name="Android.permission.DELETE_PACKAGES"/>
- <uses-permission android:name="Android.permission.CLEAR_APP_CACHE"/>
- <uses-permission android:name="Android.permission.CLEAR_APP_USER_DATA"/>
- <uses-permission android:name="Android.permission.READ_PHONE_STATE"/>
I paste the past, wow, a lot of black tea ~ How, the mouse moved up a look,
Java code
- Permission is only granted to system apps
Strange class, I this is the system application AH ~ ~ For a long time, heard a voice said to clean under, so, I clean a bit,
Dig on! @ really did not have black tea class ~ Later did not know how to change the next mainfest, and black tea, I also clean a bit, unexpectedly still useful! So, after the error, remember to clean the first OH. Of course, if you have the wrong layout file, then there is no way, you need to let the layout file to the error disappears before clean.
App Rogue Dafa apk silent installation