Launch intents using ADB

Written by Xavier Gouchet - 15 may 2014 - no comments

Sometimes, you want an Activity or a Broadcast Receiver to listen for a specific intent, which is not always easy to test. There are some applications, like With Intent which let you declare and send an intent. But you then need to be outside of your app.

I just discovered that you can use ADB to send an intent to any device (physical or emulated). Here are a couple of sample command you can run in your shell (assuming your sdk/platfor-tools is in your path) to start activities.


# specifying the action and data uri
adb shell am start -a "android.intent.action.VIEW" -d "http://developer.android.com"

# specifying the action, mime type and an extra string 
adb shell am start -a "android.intent.action.SEND" --es "android.intent.extra.TEXT" "Hello World" -t "text/plain"

# specifying an explicit component name 
adb shell am start -n "com.example.application/.MainActivity"

And of course you can also start a service or broacast an intent


# specifying an explicit component name 
adb shell am startservice -n "com.example.application/.BackgroundService"

# specifying the action
adb shell am broadcast -a "android.intent.action.PACKAGE_FIRST_LAUNCH" -d "com.example.application"

You'll find all the options you can use in the Official Documentation.

Classified in : Tools - Tags : none

Write a comment

Capcha
Enter image code :