Android Debug Bridge (ADB) is a powerful tool that allows developers to interact with their Android devices from a computer. One of its key features is the ability to start applications on the device remotely. In this tutorial, we will explore how to use ADB tools to launch Android applications.
Introduction to ADB Shell
To start an application using ADB, you need to first access the ADB shell. The ADB shell provides a command-line interface to interact with your Android device. You can access the ADB shell by running the following command in your terminal:
adb shell
This will open a new shell prompt where you can execute commands on your Android device.
Starting an Application using Activity Name
To start an application, you need to specify the package name and activity name of the application. The package name is unique to each application, and the activity name specifies which activity to launch. You can use the following command to start an application:
am start -n com.package.name/com.package.name.ActivityName
Replace com.package.name
with the actual package name of your application and ActivityName
with the actual name of the activity you want to launch.
Specifying Actions
You can also specify actions to be filtered by your intent-filters when starting an application. This is done using the -a
option followed by the action name:
am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName
Replace com.example.ACTION_NAME
with the actual action name you want to filter by.
Using the Monkey Tool
Alternatively, you can use the monkey tool to launch an application. The monkey tool generates random input for the application, but it can also be used to simply launch the application:
adb shell monkey -p your.app.package.name 1
This command will launch the default activity for the package that is in the launcher.
Creating a Script to Run an APK File
If you want to automate the process of launching an application, you can create a script that uses the aapt
tool to extract the package name and launchable activity name from an APK file. Here’s an example script:
#!/bin/bash
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
Save this script to a file (e.g., adb-run.sh
), make it executable with chmod +x adb-run.sh
, and then you can run it with an APK file as an argument:
./adb-run.sh myapp.apk
This will launch the application without requiring you to know the package name or launchable activity name.
Conclusion
In this tutorial, we explored how to use ADB tools to start Android applications. We covered how to access the ADB shell, start an application using its package and activity names, specify actions, use the monkey tool, and create a script to automate the process. With these techniques, you can easily launch Android applications on your device from your computer.