How to run a specific Android app using Terminal? [duplicate] How to run a specific Android app using Terminal? [duplicate] android android

How to run a specific Android app using Terminal? [duplicate]


Use the cmd activity start-activity (or the alternative am start) command, which is a command-line interface to the ActivityManager. Use am to start activities as shown in this help:

$ adb shell amusage: am [start|instrument]       am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]                [-c <CATEGORY> [-c <CATEGORY>] ...]                [-e <EXTRA_KEY> <EXTRA_VALUE> [-e <EXTRA_KEY> <EXTRA_VALUE> ...]                [-n <COMPONENT>] [-D] [<URI>]       ...

For example, to start the Contacts application, and supposing you know only the package name but not the Activity, you can use

$ pkg=com.google.android.contacts$ comp=$(adb shell cmd package resolve-activity --brief -c android.intent.category.LAUNCHER $pkg | tail -1)$ adb shell cmd activity start-activity $comp

or the alternative

$ adb shell am start -n $comp

See also http://www.kandroid.org/online-pdk/guide/instrumentation_testing.html (may be a copy of obsolete url : http://source.android.com/porting/instrumentation_testing.html ) for other details.

To terminate the application you can use

$ adb shell am kill com.google.android.contacts

or the more drastic

$ adb shell am force-stop com.google.android.contacts


I keep this build-and-run script handy, whenever I am working from command line:

#!/usr/bin/env bashPACKAGE=com.example.demoACTIVITY=.MainActivityAPK_LOCATION=app/build/outputs/apk/app-debug.apkecho "Package: $PACKAGE"echo "Building the project with tasks: $TASKS"./gradlew $TASKSecho "Uninstalling $PACKAGE"adb uninstall $PACKAGEecho "Installing $APK_LOCATION"adb install $APK_LOCATIONecho "Starting $ACTIVITY"adb shell am start -n $PACKAGE/$ACTIVITY


You can Start the android Service by this command.

adb shell am startservice -n packageName/.ServiceClass