There is the following code:
Process p = Runtime.getRuntime().exec("su" + "\n"); OutputStream i8 = p.getOutputStream(); i8.write(("pm install " + myApkFile.getAbsolutePath() + "\n" + "reboot" + "\n" + "exit" + "\n").getBytes("UTF-8")); i8.flush(); p.waitFor(); He installs the application. But there is a problem. The application does not have time to install, as soon as the reboot command is executed, restarting the phone. It would be nice if you first install the "pm install ..." application, wait for p.waitFor(); and then "reboot" , but it was not there. The application is updated in this way, that is, it replaces itself with a new application ( myApkFile ). If I first do "pm install ..." , then p.waitFor(); , and only then "reboot" , then nothing will come of it. If the application is replaced, then all threads, Activity , Service , Receiver and so on will be interrupted. Thus, the "reboot" command will also be unreachable (unreachable code).
Now the question. Is it possible to do something like the following su script:
pm install myApkFile.apk sleep(30 секунд) reboot exit Is it possible to somehow put this 30-second delay? I think during this time the phone will have time to install the application, and then reboot.
The "reboot" command of rebooting the phone is necessary, as there are some Services that are only launched from the BroadcastReceiver , which is activated using <action android:name="android.intent.action.BOOT_COMPLETED" /> .
Runtime...exec("su")...pm install myAPK.apk...The question is all written. - nick