Android Debug Bridge
Android Debug Bridge
This a command-line tool that lets you communicate directly with android device from your machine. It is a client-server tool that has the following components
- A client which runs on your pc and sends commands.
- A daemon(adbd) that runs as a background process on each device.
- A server which manages communication between the client and daemon. It runs on the host pc as a background process
It is included in the Android SDK platform Tools package and can also be downloaded using the command below in linux
sudo apt install adb
Once installed we can list the devices attached
adb devices -l
To send a command to a specific device from the list of attached device we use the following command
adb -s device_name install hellowolrd.apk
This command will install helloworld.apk to a device specified. incase you have only one device available you might use the command below
adb install helloworld.apk
You can also use -e option to send a command to an emulator or -d to send to hardware device
Set up port forwarding
You can also port forward the requests to a different port on a device. The following example sets up forawarding of host port 3187 to device port 5555
adb forward tcp:3187 tcp:5555
Push and pull files from a device
To copy files from a directory inside a device
adb pull remote local
To copy files to a directory inside a device
adb push local remote
example
adb push myfile.txt /sdcard/myfile.txt
Issue shell commands
You can issue android shell commands using the following command
adb shell shell_command
example
adb shell ls /system/bin
You can also get a shell from the device by using the following command
$ adb shell
shell@ $
Activity manager
Inside the adb shell you can use the activity manager to perform some actions such as start an activity, force stop a process, broadcast an intent, modify the device screen properties and more
syntax
am command
You can issue a command without entering a remote shell
adb shell am start -a android.intent.action.VIEW
example
adb shell am start -n com.example.app/.MainActivity
This starts the mainactivity of example app. You can start any activity in the app by replacing it with the .MainActivity
You can read about all activity manager commands from android
Package manager
You can use package manager(pm) to perform actions and queries on app packages installed on device.
pm command
You can issue a command without entering a remote shell. This will uninstall the specified app
adb shell pm unistall com.example.app
To install a package
pm install path_to_package
To list all packages
pm list packages
To list all users
pm list users
To print the path to a package
pm path package_name
You can read about all package manager commands from android
Device policy manager (dpm)
Helps you develop and test your device management apps
dpm command
available dpm commands from android
Take screenshot
screencap filename
example we take a screenshot and pull it
$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png
Record a video
screenrecord filename
example
$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press COntrol + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4
To learn more about the Android debug bridge and tools read this