< Irrelevant.dev

Send Specific Intent with adb

Published On: January 16, 2022 🌭?
Android CLI

There are a lot of ways to start an Android app. Often times the physical steps needed to get a specific launching intent to fire can really hamper your development flow. For example:

In order to test these entry ways quickly, and without any direct device interactions necessary, we can use adb shell am start. With this we can start an intent using the below formats:

// Specific intent, with basic DATA payload
adb shell am start -a <intent action to fire> [-d "data we want to send"]
// Specific intent with special extras
adb shell am start -a <intent action to fire> [--es "intent extra type" "intent extra data" -t "intent extra data type"]
// Specific component
adb shell am start -n "packagename/componentName"

Examples

Simulate a View action with data

Test a deeplink with this. Additionally, this is how google assistant/home actions would most likely start your app.

adb shell am start -a android.intent.action.VIEW -d "https://irrelevant.dev/posts/send-specific-intent-with-adb"

Simulate a PROCESS_TEXT action

Test a 'global search' or other text selection processing action.

adb shell am start -a "android.intent.action.PROCESS_TEXT" --es "android.intent.extra.PROCESS_TEXT" "Blood" -t "text/plain"

Launch a specific Component

Sometimes you might just want to launch your app without having to touch the device. You can start the main activity to launch normally, or pick a specific Activity component if that makes sense for your situation.

adb shell am start -n "dev.irrelevant/dev.irrelevant.features.PostsActivity"