3

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.

artem
  • 16,382
  • 34
  • 113
  • 189

2 Answers2

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
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