14 Answers

677
votes
adb shell
am start -n com.package.name/com.package.name.ActivityName

Or you can use this directly:

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

You can also specify actions to be filter by your intent-filters:

am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName 
344
votes

It's possible to run application specifying package name only using monkey tool by follow this pattern:

adb shell monkey -p your.app.package.name -c android.intent.category.LAUNCHER 1

Command is used to run app using monkey tool which generates random input for application. The last part of command is integer which specify the number of generated random input for app. In this case the number is 1, which in fact is used to launch the app (icon click).

128
votes

Or, you could use this:

adb shell am start -n com.package.name/.ActivityName
61
votes

linux/mac users can also create a script to run an apk with something like the following:

create a file named "adb-run.sh" with these 3 lines:

pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
adb shell am start -n $pkg/$act

then "chmod +x adb-run.sh" to make it executable.

now you can simply:

adb-run.sh myapp.apk

The benefit here is that you don't need to know the package name or launchable activity name. Similarly, you can create "adb-uninstall.sh myapp.apk"

Note: This requires that you have aapt in your path. You can find it under the new build tools folder in the SDK.

25
votes

Step 1: First get all the package name of the apps installed in your Device, by using:

adb shell pm list packages

Step 2: You will get all the package names, copy the one you want to start using adb.

Step 3: Add your desired package name in the below command.

adb shell monkey -p 'your package name' -v 500

For Example:
adb shell monkey -p com.estrongs.android.pop -v 500 to start the Es explorer.

23
votes

Also, I want to mention one more thing.

When you start an application from adb shell am, it automatically adds FLAG_ACTIVITY_NEW_TASK flag which makes behavior change. See the code.

For example, if you launch Play Store activity from adb shell am, pressing 'Back' button(hardware back button) wouldn't take you your app, instead it would take you previous Play Store activity if there was some(If there was not Play store task, then it would take you your app). FLAG_ACTIVITY_NEW_TASK documentation says :

if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in

This caused me to spend a few hours to find out what went wrong.

So, keep in mind that adb shell am add FLAG_ACTIVITY_NEW_TASK flag.

16
votes

We can as well start an application by knowing application type and feeding it with data:

adb shell am start -d "file:///sdcard/sample.3gp" -t "video/3gp" -a android.intent.action.VIEW

This command displays available Video Players to play sample.3gp file

14
votes

open ~/.bash_profile and add these bash functions to the end of the file

function androidinstall(){
   adb install -r ./bin/$1.apk
}
function androidrun(){
   ant clean debug
   adb shell am start -n $1/$1.$2
}

then open the Android project folder

androidinstall app-debug && androidrun com.example.app MainActivity
9
votes

monkey --pct-syskeys 0 for development boards

Without this argument, the app won't open on a development board without keys / display:

adb shell monkey --pct-syskeys 0 -p com.cirosantilli.android_cheat.textviewbold 1

and fails with error:

SYS_KEYS has no physical keys but with factor 2.0%

Tested on HiKey960, Android O AOSP.

Learned from: https://github.com/ARM-software/lisa/pull/408

Also asked at: monkey test : If the Android system doesnt has physical keys ,what are the parameters need to be includeded in the command

5
votes
adb shell am start -n '<appPackageName>/.<appActitivityName>

Ex:

adb shell am start -n 'com.android.settings/.wifi.WifiStatusTest'

You can use APK-INFO application to know the list of App Activities with respect to each App Package

2
votes

You can find your app package name by below command:

adb shell pm list packages

Above command returns package list of all apps, Example:

org.linphone.debug
.
.
com.android.email

Now I want to start app linphone by using below command and this worked for me:

adb shell am start org.belphone.debug
1
votes

The shortest command yet is the following:

adb shell monkey -p your.app.package.name 1

This will launch the default activity for the package that is in the launcher.

Thanks to @Androiderson for the tip

0
votes

Try this, for opening an android photo app & with specific image file to open as parameter.

adb shell am start -n com.google.android.apps.photos/.home.HomeActivity -d file:///mnt/user/0/primary/Pictures/Screenshots/Screenshot.png

It will work on latest android, no pop up will come to select an application to open as you are giving specific app to which you want to open your image with

0
votes
adb shell am start -n com.app.package.name/com.java.package.name.ActivityName

Example

adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.search.core.google.GoogleSearch

If the Java package is the same, then it can be shortened

adb shell am start -n com.example.package/.subpackage.ActivityName