I'm writing the MDM app, that can update itself via PM (pm install -r my.apk
).
A several services in my app should be started after update. Can I do this? Devices are rooted.
Asked
Active
Viewed 1,246 times
3

artem
- 16,382
- 34
- 113
- 189
2 Answers
2
Actually, it is possible.
I had the same issue, i needed to update my app and restart it afterwards. I solved it like this:
String command = "pm install -r " + filename + ";am start -n com.example.myapp/com.example.myapp.Start";
This will install your app, and afterwards call "am start" to launch the app again. Just replace com.example.myapp with your package name, and the parameter after the / is the activity you want to launch.
I know this is an old post, but i came across it when i was searching for a solution, so maybe this can help others in the future :)

Dan
- 1,451
- 1
- 11
- 8
-
2It works on one of my devices (Android 4.4, but doesn't work on the other - Android 5.1). I haven't found a way (yet) to make it work on both – Marcin Mar 20 '17 at 07:55
-
Are both devices rooted? – Dan Apr 05 '17 at 11:45
-
I can confirm that this works on android 4.4 but not android 5.1 (both rooted devices) – Joel Oct 11 '19 at 01:32
1
I am afraid that self update is not possible. While self updating your app, system will kill process performing update.
You have two options:
- create second app that will execute
pm install -r my.apk
safely - create simple update script in shell and make it run on device boot

Dominik Suszczewicz
- 1,469
- 2
- 16
- 23
-
@Dan i try to use your solution but sometime it works and sometime it unable to launch back main activity. Is there any other suitable way to do this as i dont want to make a separate application for this purpose. I have rooted device so may be there is a way to restart application main activity using command only. – user565 Mar 27 '18 at 16:19