1

I'm trying to update an app remotely. All devices are rooted. Due to the nature of the apps and devices, there are no users, the devices monitor a range of sensors and send the info back to a server from key locations.

I know that

"pm install -r  app.apk\n"

will install a downloaded apk. But how would I get it to run without a user. Once this command executes the app stops and all it's services stop aswell.

So is there a command to install + run ?

am start -n com.package.name/com.package.name.ActivityName

does not get executed and wont start the services because this code is not reached after the install command

edit:

this is the code once the apk is downloaded

dataOutputStream.WriteBytes("mount -o rw,remount -t /system\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("chmod -R 777 "+localPath+"\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("mount -o ro,remount -t /system\n");
dataOutputStream.Flush();
dataOutputStream.WriteBytes("pm install -r  "+localPath+"\n");
dataOutputStream.Flush();

//The code below is not reached because the install kills the app

dataOutputStream.WriteBytes("am start -n com.company.remote/com.company.remote.RebootServices\n");
dataOutputStream.Flush();
Migz
  • 163
  • 1
  • 13
  • 1
    Possible duplicate of [How to start an application using android ADB tools?](http://stackoverflow.com/questions/4567904/how-to-start-an-application-using-android-adb-tools) – SushiHangover Oct 05 '16 at 11:38

1 Answers1

0

Whenever you install an app through Android Studio, it installs your app and launches it immediately afterwards. By looking into the commands it executes, I have found the following line, it might help you:

adb shell am start -n "com.package.name/com.package.name.ActivityName" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Notice the intent filter flags: -a for "action" and -c for "category" as defined in manifest. If you have an intent filter, you can use those too.

EDIT: After reading the comment of SushiHangover, this is indeed a duplicate of this question: https://stackoverflow.com/a/4567928/3673616

According to the answer from there, instead of am start[...] you need to use adb shell am start[...]

Community
  • 1
  • 1
techfly
  • 1,826
  • 3
  • 25
  • 31
  • this code is internal to the app, adb shell is not applicable in this case .. my problem is once the app update is installed (via su command) my app stops automatically before the start command can be executed – Migz Oct 05 '16 at 12:33
  • @Migz You would need a bootstrapping app that has a service that is always running to do that. If the bootstrapping service sees that other app is not running, it creates an intent and starts the other app. – SushiHangover Oct 06 '16 at 02:39