ADB-The Most useful tool in Android
ADB (Android Debug Bridge)
ADB is a command-line tool that lets you communicate with connected devices. It provides various device actions like clear app data, debugging apps, see device stats, capture screenshot etc..
In this article we’ll cover usage of some of the most useful commands of ADB.
ADB Shell
In adb you can start shell script and run shell commands like ls, rm, mkdir, netstat, dumpsys etc...
I find ls quite useful whenever i have to pull and push file between system and device it helps me finding files location on device
adb shell ls
you can see sdcard in image right? Our device files are stored there we can use cd, ls to find files then use pull and push command to move files
ADB Pull and Push
Passing files between Device and System(Laptop or PC).
Push: Moving file from system to device.
adb push system-file-path device-file-pathe.g:
adb push /Users/.../screen.png /sdcard/screenshots/screen.png
Pull: Fetching files from device to system
adb pull source destinatione.g.
adb pull /sdcard/screenshots/screen.png
If destination isn’t provided then file will be pulled to current directory opened in your Terminal.
ADB Screenshot
Capturing screenshot using screencap command.
adb shell screencap /sdcard/screen.png
ADB Install/Uninstall
To install an APK either release or debug use
adb install /path-to-apk/app-debug.apk
Sometimes we want to install an updated APK over existing there we need to specify a release flag like -r
adb install -r .../app-release.apk
To uninstall an apk
adb uninstall com.balsikandar.adbtest.debug
ADB Screen Record
This one is mostly useful for Testers. I said testers because they can start recording before doing manual testing and share recordings if any issue occurs.
adb shell screenrecord /path-on-device/recording.mp4
By default we can record a video of at max 3 minutes but it can be changed by specifying time-limit
property
adb shell screenrecord /sdcard/recording.mp4 --time-limit 20
There are many other properties which we can specify. Use help to know details
adb shell screenrecord --help
ADB am (Activity Manager)
am can be used to stuffs like broadcasting intent starting an activity or opening settings screen. Try below command to check what am provides.
adb shell am ## --help
Let’s look at some of the Examples:
Note: -a represents action, -c represents category and -n represents component and -d is data
Making a Call
To make a call use -a android.intent.action.CALL
adb shell am start -a android.intent.action.CALL -d tel:88******97
Force stop an app
To force stop an app provide it’s packageName
adb shell am force-stop com.balsikandar.adbtest.debug
Open google map
Either you can provide latitude and longitude as below
adb shell am start -a android.intent.action.VIEW -d 'geo:28.65381,77.22897'
Or you can query the address using q=search address
adb shell am start -a android.intent.action.VIEW -d 'geo:0,0?q=ban'
Opening a Url
To open a url use am(Activity Manager) with
adb shell am start -a android.intent.action.VIEW -d http://okcredit.in
Opening IME Settings
adb shell am start -a android.settings.INPUT_METHOD_SETTINGS
Broadcasting Intent
adb shell am broadcast android.net.conn.CONNECTIVITY_CHANGE
pm(Package manager)
pm also provides several useful commands
To see everything which pm provides run
adb shell pm ## --help
To view packages of all installed apps we can use
adb shell pm list packages
Enable disable Wifi
i know not very useful but it’s there
adb shell svc wifi disable
adb shell svc wifi enable
There is many more which you can find and let me know too but these are i often use to save my time and debug my apps.
Some useful References:
I like ADB idea a lot. You should give it a try