This article will introduce how to start an activity from adb command in Android.
- 1. Start an activity by "adb shell am start"
- 2. Example: Start an Intent with only Action
- 3. Example: Start an Intent with Action and Category
- 4. Example: Start an Intent with Action and Data
- 5. Example: Start an Intent with Action and Package
- 6. Example: Start an Intent with Action, Package and Component
- 7. Reference: Intent Setting Options
1. Start an activity by "adb shell am start"
The adb shell am start <Intent>
command can be used to launch an activity for the given Intent.
Intents can be defined as an option in a command. For more detailed settings, please refer to the "Reference: Intent Setting Options" at the bottom of the article.
2. Example: Start an Intent with only Action
If you define an intent with the -a
option after the adb shell am start
command, an intent with only the Action will be started.
$ adb shell am start -a android.intent.action.MY_ACTION
Output:
Starting: Intent { act=android.intent.action.MY_ACTION }
3. Example: Start an Intent with Action and Category
You can add a Category using the -c
option.
If there are two categories, you can enter them multiple times like -c AAA -c BBB
.
$ adb shell am start -a android.intent.action.MY_ACTION -c android.intent.category.MY_CATEGORY
4. Example: Start an Intent with Action and Data
If you input a Uri with the -d
option, an Intent with the data of the Uri will be executed.
$ adb shell am start -a android.intent.action.MAIN -d https://google.com
5. Example: Start an Intent with Action and Package
You can start an Intent with the -p
option set to the Package.
$ adb shell am start -a android.intent.action.MAIN -p com.example.myapp
6. Example: Start an Intent with Action, Package and Component
You can start an Intent with the -n
option set for the Package and Component.
$ adb shell am start -a android.intent.action.MAIN -n com.example.myapp/com.example.myapp.MainActivity
7. Reference: Intent Setting Options
This is an option used when defining an intent from ADB command.
<INTENT> specifications include these flags and arguments:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-i <IDENTIFIER>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-n <COMPONENT_NAME>]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer[])
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long[])
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float[])
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String[]; to embed a comma into a string,
escape it using "\,")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using "\,")
Related Posts
- How to download and build Android 13, AOSP
- Notification permission request, pop up notification in Android 13
- Resolve `Access blocked: ComponentInfo` error on Android 13
- Fix error "android gradle plugin requires java 11 to run. you are currently using java 1.8."
- Android - Vibration, Vibrator, VibrationEffect example
- How to get phone number in Android
- How to create Bugreports and Logcat with ADB in Android
- Clear application user data with ADB in Android
- How to disable/enable apps with ADB in Android
- How to find PID of a package with adb in Android
- How to grant/revoke permissions with adb in Android
- How to install an apk(app) with adb in Android
- How to kill a process/package from ADB in Android
- How to transfer files using adb push/pull command in Android
- How to capture the screen from adb in Android
- How to uninstall/install system apps from adb in Android
- How to change Settings values from adb in Android
- How to Factory reset with ADB in Android
- How to get logcat from ADB command in Android
- How to capture Heap Dump from app with ADB in Android
- How to force stop an app with adb in Android
- How to start/stop a service from adb in Android
- How to send/broadcast an intent from adb command in Android
- How to start an activity from adb in Android
- How to generate input from adb in Android
- How to check SQLite DB table in Android Studio
- How to get memory info and thread list from adb in Android
- Android - Uri, Scheme and SSP(Scheme Specific Part)
- How to parse a xml file with XmlResourceParser in Android
- Android - Signing an apk with Platfom key
- How to fix "Cleartext HTTP ... not permitted" for Android development
- How to fix "kvm permission denied" for Android Emulator
- Using ADB over Wifi for Android development