Android Debug Bridge is command line utility to communicate with the Android device that is connected either via USB or Wi-Fi, or with an emulator(Android virtual device) running on the development machine.
adb devices –l
adb logcat –c
adb -s <serial_number_of_device> <command>
Collect logcat continuously and save to a file (-v time, logs the time. -b all, logs all buffers). It should be stopped explicitly.
adb logcat –v time –b all > my-logcat.txt
adb logcat –v time –b all –d > dump-logcat.txt
adb bugreport > bugreport.txt
adb bugreport
adb logcat -b all -G 16777216
adb shell pm list packages
adb shell pm list packages -3
adb shell pm list packages -s
adb shell pm list packages -e
adb shell pm list packages -d
adb shell pm disable <package_name>
adb shell pm enable <package_name>
adb shell getprop ro.build.type
adb shell getprop ro.build.display.id
adb shell getprop ro.build.fingerprint
adb shell input keyevent <KEYCODE>
Keycodes are
adb shell input keyevent KEYCODE_MENU
adb shell input keyevent KEYCODE_HOME
adb shell input keyevent KEYCODE_BACK
adb push <path_to_src_file_in_pc> <path_to_dest_file_in_device>
adb pull <path_to_src_file_in_device> <path_to_dest_file_in_pc>
adb reboot
adb reboot bootloader
adb reboot recovery
adb shell screencap /sdcard/my_snap.png
Image will be stored in sdcard, it needs to be pulled into the PC by using adb pull command
adb screenrecord /sdcard/my_video.mp4
Records for a maximum(default) 3 minutes
adb shell input text <mytext>
//Spaces are not allowed in text
adb install <path_to_apk_in_pc>
Re-install an app . If the app is already installed , it will be uninstalled before installing again
adb install –r <path_to_apk_in_pc>
adb install –s <path_to_apk_in_pc>
adb uninstall <package_name_of_the_application>
adb shell getprop ro.build.version.sdk
adb shell am force-stop <package_name_of_the_application>
adb remount
adb shell getenforce
adb shell setenforce 1
adb shell setenforce 0
Connect ADB over WiFi
1. Connect device and PC to the same network
2. Connect device over USB cable and Enable USB Debugging in device
3. Once detected over USB, run
adb tcpip 5555
// this restarts adb in device
4. Disconnect USB cable now, and run
adb connect <device_ip_address>:5555
//this restarts adb to communicate over WiFi with input IP address
5. To disconnect adb from WiFi mode run
adb disconnect <device_ip_address>:5555
Start an actiivty from adb
We can start any activity from adb commands either explicitly by mentioning the name of the package and name of the class, or implicitly by just the name of intent action.
Implicit intent to launch settings application
adb shell am start -a android.settings.SETTINGS
Launch Bluetooth settings
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
Explicit intent to launch settings app using name of the package and activity class. You must know the name of activity class to launch it via adb
adb shell am start -n com.android.settings/.Settings
Pass extras for the intent via adb to start an activity.
1. Open google.com by sending an adb command
adb shell am start -a android.intent.action.VIEW -t text/html -d http://www.google.com
// Here android.intent.action.VIEW is standard intent action, -t text/html is the mimetype of the data sent with intent, -d <url> is the data to be used by the intent.
2. Open an image in Photos application
adb shell am start -a android.intent.action.VIEW -t image/* -d /sdcard/abc.png
// ensure you have abc.png in /sdcard/
3. Open camera application to capture an image
adb shell am start -a android.media.action.IMAGE_CAPTURE
Intent actions for all settings can be found here
adb shell cmd netpolicy set restrict-background true
adb shell cmd netpolicy set restrict-background false
adb shell cmd netpolicy add restrict-background-whitelist <package_name>
adb shell cmd netpolicy add restrict-background-whitelist <package_name>
adb shell cmd netpolicy list wifi-networks
adb shell cmd netpolicy set metered-network <WIFI_SSID> true
adb shell dumpsys battery unplug
adb shell dumpsys battery reset
adb shell dumpsys battery unplug
adb shell am set-inactive <package_name> true
adb shell am set-inactive <package_name> false