ADB (Android Debug Bridge)
ADB (Android Debug Bridge) is a command line tool that used to communicate with an emulator instance or connected Android device.
A large portion of this topic was split out to adb shell
List of examples moved to adb shell:
- Granting & revoking API 23+ permissions
- Send text, key pressed and touch events to Android Device via ADB
- List packages
- Recording the display
- Open Developer Options
- Set Date/Time via adb
- Changing file permissions using chmod command
- Generating a "Boot Complete" broadcast
- Print application data
- View external/secondary storage content
- kill a process inside an Android device
You can use the
adb backup command to backup your device.
-f <filename> specify filename default: creates backup.ab in the current directory
-apk|noapk enable/disable backup of .apks themself default: -noapk
-obb|noobb enable/disable backup of additional files default: -noobb
-shared|noshared backup device's shared storage / SD card contents default: -noshared
-all backup all installed apllications
-system|nosystem include system applications default: -system
<packages> a list of packages to be backed up (e.g. com.example.android.myapp) (not needed if
-all is specified)
For a full device backup, including everything, use
Note: Doing a full backup can take a long time.
In order to restore a backup, use
Clear application data
One can clear the user data of a specific app using
This is the same as to browse the settings on the phone, select the app and press on the clear data button.
pminvokes the package manager on the device
cleardeletes all data associated with a package
Connect ADB to a device via WiFi
The standard ADB configuration involves a USB connection to a physical device.
If you prefer, you can switch over to TCP/IP mode, and connect ADB via WiFi instead.
Not rooted device
Get on the same network:
- Make sure your device and your computer are on the same network.
Connect the device to the host computer with a USB cable.
adbto device over network:
While your device is connected to
adbvia USB, do the following command to listen for a TCP/IP connection on a port (default 5555):
adb tcpip <port>(switch to TCP/IP mode).
- Disconnect the USB cable from the target device.
adb connect <ip address>:<port>(port is optional; default 5555).
If you don't know your device's IP you can:
- check the IP in the WiFi settings of your device.
- use ADB to discover IP (via USB):
- Connect the device to the computer via USB
- In a command line, type
adb shell ifconfigand copy your device's IP address
To revert back to debugging via USB use the following command:
You can also connect ADB via WiFi by installing a plugin to Android Studio. In order to do so, go to Settings > Plugins and Browse repositories, search for ADB WiFi, install it, and reopen Android Studio. You will see a new icon in your toolbar as shown in the following image. Connect the device to the host computer via USB and click on this AndroidWiFiADB icon. It will display a message whether your device is connected or not. Once it gets connected you can unplug your USB.
Note: Some devices which are rooted can use the ADB WiFi App from the Play Store to enable this in a simple way. Also, for certain devices (especially those with CyanogenMod ROMs) this option is present in the Developer Options among the Settings. Enabling it will give you the IP address and port number required to connect to
adb by simply executing
adb connect <ip address>:<port>.
When you have a rooted device but don't have access to a USB cable
The process is explained in detail in the following answer: http://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp/3623727#3623727 The most important commands are shown below.
Open a terminal in the device and type the following:
And on your computer:
To turn it off:
adb will timeout after 5000 ms. This can happen in some cases such as slow WiFi or large APK.
A simple change in the Gradle configuration can do the trick:
Connect device by IP
Enter these commands in Android device Terminal
After this, you can use CMD and ADB to connect using the following command
And you can disable it and return ADB to listening on USB with
From a computer, if you have USB access already (no root required)
It is even easier to switch to using Wi-Fi, if you already have USB. From a command line on the computer that has the device connected via USB, issue the commands
Replace 192.168.0.101 with device IP
Direct ADB command to specific device in a multi-device setting
1. Target a device by serial number
-s option followed by a device name to select on which device the
adb command should run.
-s options should be first in line, before the command.
2. Target a device, when only one device type is connected
You can target the only running emulator with -e
Or you can target the only connected USB device with -d
Install ADB on Linux system
How to install the Android Debugging Bridge (ADB) to a Linux system with the terminal using your distro's repositories.
Install to Ubuntu/Debian system via apt:
Install to Fedora/CentOS system via yum:
Install to Gentoo system with portage:
Install to openSUSE system with zypper:
Install to Arch system with pacman:
Install and run an application
To install an APK file, use the following command:
or if the app is existing and we want to reinstall
To uninstall an application, we have to specify its package
Use the following command to start an app with a provided package name (or a specific activity in an app):
For example, to start Waze:
List all permissions that require runtime grant from users on Android 6.0
Print verbose list of connected devices
To get a verbose list of all devices connected to
adb, write the following command in your terminal:
- The first column is the serial number of the device. If it starts with
emulator-, this device is an emulator.
usb:the path of the device in the USB subsystem.
product:the product code of the device. This is very manufacturer-specific, and as you can see in the case of the Archos device
A50PLabove, it can be blank.
model:the device model. Like
product, can be empty.
device:the device code. This is also very manufacturer-specific, and can be empty.
Pull (push) files from (to) the device
You may pull (download) files from the device by executing the following command:
You may also push (upload) files from your computer to the device:
Example to Retrieve Database from device
Read device information
Write the following command in your terminal:
This will print all available information in the form of key/value pairs.
You can just read specific information by appending the name of a specific key to the command. For example:
Here are a few interesting pieces of information that you cat get:
ro.product.model: Model name of the device (e.g. Nexus 6P)
ro.build.version.sdk: API Level of the device (e.g. 23)
ro.product.brand: Branding of the device (e.g. Samsung)
Full Example Output
You can reboot your device by executing the following command:
Perform this command to reboot into bootloader:
Reboot to recovery mode:
Be aware that the device won't shutdown first!
It's possible to send broadcast to
In this example we are sending broadcast with action
com.test.app.ACTION and string extra in bundle
You can put any other supported type to bundle, not only strings:
--ez - boolean
--ei - integer
--el - long
--ef - float
--eu - uri
--eia - int array (separated by ',')
--ela - long array (separated by ',')
--efa - float array (separated by ',')
--esa - string array (separated by ',')
To send intent to specific package/class
-p parameter can be used.
Sending to package:
Sending to a specific component (
SomeReceiver class in
- Sending a "boot complete" broadcast
- Sending a "time changed" broadcast after setting time via adb command
Taking a screenshot and video (for kitkat only) from a device display
Screen shot: Option 1 (pure adb)
shell adb command allows us to execute commands using a device's built-in shell. The
screencap shell command captures the content currently visible on a device and saves it into a given image file, e.g.
You can then use the pull command to download the file from the device into the current directory on you computer:
Screen shot:Option 2 (faster)
Execute the following one-liner:
(Marshmallow and earlier):
(Nougat and later):
-p flag redirects the output of the
screencap command to stdout. The Perl expression this is piped into cleans up some end-of-line issues on Marshmallow and earlier. The stream is then written to a file named
screen.png within the current directory. See this article and this article for more information.
this only work in KitKat and via ADB only. This not Working below Kitkat To start recording your device’s screen, run the following command:
adb shell screenrecord /sdcard/example.mp4, This command will start recording your device’s screen using the default settings and save the resulting video to a file at
/sdcard/example.mp4 file on your device.
When you’re done recording, press Ctrl+C (z in Linux) in the Command Prompt window to stop the screen recording. You can then find the screen recording file at the location you specified. Note that the screen recording is saved to your device’s internal storage, not to your computer.
The default settings are to use your device’s standard screen resolution, encode the video at a bitrate of 4Mbps, and set the maximum screen recording time to 180 seconds. For more information about the command-line options you can use, run the following command:
adb shell screenrecord –help, This works without rooting the device. Hope this helps.
Turn on/off Wifi
View activity stack
Very useful when used together with the
watch unix command:
View an app's internal data (data/data/
) on a device
First, make sure your app can be backed up in
android:allowBackup is not
Create a tar with dd command:
Extract the tar:
You may then view the extracted content.
View and pull cache files of an app
You may use this command for listing the files for your own debuggable apk:
And this script for pulling from cache, this copy the content to sdcard first, pull and then remove it at the end:
Then you can pull a file from cache like this:
Get Database file via ADB
View available devices
First column - device serial number
Second column - connection status
You can run
logcat as an adb command or directly in a shell prompt of your emulator or connected device. To view log output using
adb, navigate to your SDK platform-tools/ directory and execute:
Alternatively, you can create a shell connection to a device and then execute:
One useful command is:
This displays the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message in a long message format.
Logcat logs got so called log levels:
V — Verbose, D — Debug, I — Info, W — Warning, E — Error, F — Fatal, S — Silent
You can filter logcat by log level as well. For instance if you want only to output Debug level:
Logcat can be filtered by a package name, of course you can combine it with the log level filter:
You can also filter the log using grep (more on filtering logcat output here):
In Windows, filter can be used using findstr, for example:
To view alternative log buffer [main|events|radio], run the
logcat with the
Save output in file :
Save output in file while also watching it:
Cleaning the logs: