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:
Launching a Deeplink
You need to get the link on the device, in a way you can tap it. You have to open the app that contains the link, find it, and tap on the link. This is a hassle to flip between apps, and extremely error prone when testing multiple different deeplinks.
Launching from a Google Action (google home, google assistant integrations)
Similar to deeplinking, but you need to generate the steps in the Home/Assistant to trigger the Google Action that will fire for your device. Additionally, there may be environmental/test limitations to getting Actions to fire on non-signed devices.
Global PROCESS_TEXT Actions
For these, you need to find the text you want to select in another app, select the text, find your exposed action in the context menu, and tap it.
Any custom intents with special data
There are many scenarios where building up the right data for a custom intent could be cumbersome, and we'd really like to just script some of the data for testing.
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"