596

How do I send an intent using Android's ADB tools?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sean
  • 6,785
  • 7
  • 23
  • 26

18 Answers18

740
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 
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • 27
    Thank you very much , i've made it shell function in ~/.bash_profile to be much faster `function androidrun(){ ant clean debug adb shell am start -n $1/$1.MainActivity }` and its usage `androidrun com.example.test` – AbdullahDiaa Feb 16 '13 at 12:43
  • 3
    `adb shell am` will give you a list of other options to pass to the `am` command. You can find out more at https://developer.android.com/tools/help/adb.html#am – Ehtesh Choudhury May 14 '13 at 23:17
  • 1
    @shurane How can I find -a option? – ericyoung May 28 '13 at 14:33
  • @ericyoung I don't have access to a device offhand, but you can try just running `adb shell am`, which will list some more detailed help compared to the documentation. – Ehtesh Choudhury May 28 '13 at 15:10
  • 32
    is is possible to run the default activity, instead of being so specific to which activity i intend it should start? – android developer Jul 25 '13 at 08:23
  • AFAIK, you can omit part of the command like in Joilnen answer – Cristian Jul 25 '13 at 21:42
  • 3
    I had problems finding the application and activity. I used this pipe line `adb logcat | grep --line-buffered ActivityManager | grep --line-buffered` to list all applications that were displayed. – Att Righ Mar 10 '17 at 20:07
  • Can you add an example of how to launch it with a deep link? – inder Sep 16 '17 at 14:26
  • https://stackoverflow.com/a/5494891/236465 shows how to use `cmd` and how to obtain the Activity name knowing the package – Diego Torres Milano Apr 20 '18 at 05:30
  • This answer works on Oculus Go (as there is no way on its UI to run normal android apps) but it displays a non-VR view of the app. However, if your install and run your app through visual studio, you see the VR view of your app! – Kamran Bigdely Aug 09 '19 at 20:46
  • If you have a dollar sign in an activity name, use 3 backslashes to escape it, e.g. `adb shell "am start -a android.settings.SYNC_SETTINGS -n com.android.settings/.Settings\\\$AccountDashboardActivity"` – 4emodan Oct 05 '22 at 11:26
  • `com.package.name/com.package.name.ActivityName`, can be shortened/reduced to, `com.package.name/.ActivityName` – evandrix Feb 23 '23 at 18:58
413

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

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michal
  • 6,453
  • 2
  • 24
  • 23
  • 142
    Launcher is default. You can simplify to `adb shell monkey -p your.app.package.name 1` – Androiderson Oct 28 '15 at 16:06
  • 3
    Is it possible to use the APK file name, instead of the package name? Suppose I have an APK file, and I want to be able to install&run it, is it possible? – android developer Jun 15 '16 at 07:42
  • 3
    What if I get an error: **no activities found to run. aborting**? – IgorGanapolsky Aug 04 '16 at 21:05
  • 3
    @IgorGanapolsky if no activities found, it's a Service app and has no Activity at all. – m3nda Sep 06 '16 at 08:42
  • `--pct-syskeys 0` is required for devboards: https://stackoverflow.com/a/46935109/895245 – Ciro Santilli OurBigBook.com Oct 25 '17 at 14:31
  • @WSS im sorry but i think you're wrong. An visible APP has main activity at least. If you don't have activity nothing will happen except the case that you init a service at launch, ie notification app. Take a read: https://www.quora.com/Can-an-Android-app-be-made-without-an-activity. Regards. – m3nda Apr 20 '18 at 23:21
  • @erm3nda sorry, I was wrong and that app worked. Since the app was open source I imported its project, but it has some problems and it caused it to fail. – WSS Apr 21 '18 at 17:31
  • @WSS no worries :) – m3nda Apr 22 '18 at 00:40
  • 1
    @IgorGanapolsky if it is a service use `adb shell am startservice com.some.package.name/.YourServiceSubClassName` see here: https://stackoverflow.com/a/18703083/211292 – ThomasW Mar 25 '19 at 05:52
  • This should be the accepted answer. In particular, Androiderson's comment. – Shenk Apr 26 '19 at 15:59
  • @androiddeveloper You can use the android tools to get the android package name and then launch that. See here: https://stackoverflow.com/questions/6289149/read-the-package-name-of-an-android-apk – James Riordan May 02 '19 at 10:17
  • I found this to be the most useful technique because it only requires the package name and not the name of the launcher activity. – Merc May 03 '19 at 16:05
  • ty, best answer I have got. – AbstProcDo Jul 07 '21 at 07:03
  • This helps me to launch gmail app. Thanks! To launch gmail app using adb shell `adb shell monkey -p com.google.android.gm -c android.intent.category.LAUNCHER 1` – miltonbhowmick Jul 26 '22 at 11:41
  • It works, but has problems: 1) will launch random activity every time, 2) cannot add deeplink string. If you get `** No activities found to run, monkey aborted.` check that you didn't unistall an app. – CoolMind Mar 17 '23 at 07:31
134

Or, you could use this:

adb shell am start -n com.package.name/.ActivityName
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
Joilnen
  • 1,341
  • 1
  • 8
  • 2
  • 86
    is it possible to do it without specifying the activity name, so that the default main activity will start? – android developer May 16 '13 at 11:13
  • 5
    @androiddeveloper See the *monkey* command below from *depodefi*: no need to specify activity name! – 1111161171159459134 Feb 28 '15 at 08:17
  • @DanielBeauyat Nice. it works even on a device. Here's the link to the post, BTW: http://stackoverflow.com/a/25398877/878126 – android developer Feb 28 '15 at 10:52
  • It should be noted that if you use an `applicationIdSuffix` such as `.debug` for your debug builds, you have to use the fully qualified activity name: `adb shell am start -n com.package.name.debug/com.package.name.ActivityName`. The suffix only applies to the application id, not the package name of the java classes. – friederbluemle Feb 05 '16 at 13:20
  • 14
    What if I don't know the **ActivityName**? – IgorGanapolsky Sep 01 '16 at 13:27
  • 2
    Run ~/android-sdk-linux/build-tools/20.0.0/aapt dump badging yourapp.apk , which will list the following entry: launchable-activity: name='com.company.android.package.YourLaunchableActivity' – JohnyTex Sep 16 '16 at 09:59
  • 22
    `monkey -p com.package.name 1` via `adb shell` – Denys Vitali Dec 16 '16 at 12:26
65

Linux and Mac users can also create a script to run an APK file with something like the following:

Create a file named "adb-run.sh" with these three 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 Android Asset Packaging Tool (aapt) in your path. You can find it under the new build tools folder in the SDK.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dljava
  • 1,825
  • 17
  • 14
  • for windows you can try with cygwin (untested) – dljava Jun 25 '13 at 06:17
  • 3
    Your post made me look up AWK. I went ahead and re-created your script. http://pastebin.com/X7X1SsFa – Kyle Dec 06 '13 at 16:20
  • 2
    This is fabulous. Why this isn't a standard adb command we'll never know. – John Tyree Jun 08 '14 at 07:51
  • You won't need to have aapt in your path (as long as "android" is) if you set the PATH in the adb-run.sh script, like this: PATH=$(dirname $(which android))/../build-tools/20.0.0:$PATH – Steve Lemke Oct 23 '14 at 20:16
  • @dljava why does this not work on https://play.google.com/store/apps/details?id=com.amaze.filemanager ? – WSS Apr 18 '18 at 19:53
  • This answer is a real Good asset. I substituted aapt with : $HOME/Library/Android/sdk/build-tools//aapt – JeanCarlos Chavarria Oct 09 '18 at 00:17
  • Note that there might be more than one launchable activity in one apk (I think) -- besides it might be better to run aapt only once... – user202729 Jan 22 '21 at 11:26
39

Step 1: First get all the package names 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tushar Pandey
  • 521
  • 5
  • 9
  • 24
    This will launch your application and send 500 pseudo-random events to it. So use '1' to replace '500' is better. – Lyn Dec 26 '18 at 07:11
  • What is "Es explorer"? For example, can you [add](https://stackoverflow.com/posts/50225901/edit) a reference to it? (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Nov 08 '21 at 14:04
29

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Louis CAD
  • 10,965
  • 2
  • 39
  • 58
25

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 a Play Store activity from adb shell am, pressing the 'Back' button (hardware back button) wouldn't take you back to your app. Instead, it would take you to the previous Play Store activity if there was some (if there was not a Play store task, then it would take you back to 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.

Community
  • 1
  • 1
김준호
  • 15,997
  • 9
  • 44
  • 38
  • 1
    Also, worth mentioning that that there is no way to clear said flag, which is annoying – Kedar Paranjape Jul 17 '19 at 21:26
  • would it help to supply the flag (-f) FLAG_ACTIVITY_CLEAR_TASK? – user228505 Sep 17 '20 at 16:14
  • 1
    What do you mean by *"take you your app"* (seems incomprehensible. ***Two*** instances)? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/23864073/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Nov 08 '21 at 13:42
17

We can as well start an application by knowing the 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 a sample.3gp file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anvesh Yalamarthy
  • 1,625
  • 20
  • 36
17

You can find your app package name by the below command:

adb shell pm list packages

The above command returns a package list of all apps. Example:

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

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

adb shell am start org.linphone.debug
Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25
  • 2
    Hmm, didn't work on Android 4.4. 1. the package names are all prefixed with `package:` (e.g. `package:com.cnn.mobile.android.phone`). 2. When trying to launch (with or without the `package:` prefix), I get `Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.cnn.mobile.android.phone } Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.cnn.mobile.android.phone }`. – Joshua Pinter Oct 20 '21 at 14:45
15

Open file ~/.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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AbdullahDiaa
  • 1,316
  • 16
  • 17
11

monkey --pct-syskeys 0 for development boards

This argument is needed for development boards without keys/display:

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

Without it, the app won't open, and you will get an error message like:

SYS_KEYS has no physical keys but with factor 2.0%

It was tested on HiKey960, Android O AOSP.

Learned from: this GitHub issue

Also asked at: How to use the monkey command with an Android system that doesn't have physical keys?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
8

Use:

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

To get <appPackageName> run :

adb shell pm list packages

To get <appActitivityName> lunch app and run

adb shell dumpsys window | grep -E 'mCurrentFocus'

yohan
  • 81
  • 1
  • 2
6

Use:

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

Example:

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

You can use the APK-INFO application to know the list of app activities with respect to each app package.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ImSaleem
  • 81
  • 1
  • 6
  • 2
    your example codes don't show usage of ` APK-INFO` – Zimba May 10 '21 at 04:23
  • What is "APK-INFO"? For example, can you [add](https://stackoverflow.com/posts/50225901/edit) a reference to it? (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Nov 08 '21 at 14:00
2
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rds
  • 26,253
  • 19
  • 107
  • 134
1

The right way would be to use cmd package resolve-activity to find the startup activity before launching, so you can launch with

am start $(cmd package resolve-activity --brief com.package.name | tail -n 1)

caiohamamura
  • 2,260
  • 21
  • 23
0

Try this, for opening an Android photo app and with the specific image file to open as a 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 version of Android. No pop up will come to select an application to open as you are giving the specific app to which you want to open your image with.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Varun Sharma
  • 530
  • 5
  • 10
  • I have a player app, which is able to stream a video from url, how can i pass this url as a parameter and stream from that url? suppose a url from youtube? – Vishnu Feb 06 '18 at 12:13
0

When you try to open a Flutter app, you can use this command:

adb shell am start -n com.package.name/io.flutter.embedding.android.FlutterActivity

Replace com.package.name with your package name. You find your package in your app/build.gradle at applicationId.

Nils Reichardt
  • 3,195
  • 2
  • 18
  • 28
0

To guarantee support for Android TV as well as non-Android TV apps:

adb shell "monkey -p com.package.name -c android.intent.category.LEANBACK_LAUNCHER 1 || monkey -p com.package.name -c android.intent.category.LAUNCHER 1"
barkside
  • 3,951
  • 4
  • 23
  • 32