The Android Debug Bridge ( ADB ) is an underutilised tool in my opinion.
Over the last couple of months I have been doing a lot of work using Cordova and the Ionic Framework to create my field guide to NSW Marine Life for the Android platform.
When I started out working with Android my work flow was pretty simple:
- Make the required changes to the application code
- Test in a browser using the simple web server provided with Python package
- Use Cordova build command to build an apk package for testing on an actual Android device
- Push the compiled package to the test device using adb to install the package on a device with developer model enable
Over time as my familiarity with the Android tool chain progressed. I found the Android Debug Bridge ( adb ) tool that makes up part of the Android SDK has a lot more to offer. Below are some of handy tips I have found with adb that can make a developers life a little bit easier.
Wake / Unlock / Lock a Device
Using adb you can wake a device from a sleep state without touching the device.
adb shell input keyevent 82
Alternately you can also send an awake device to sleep with the command.
adb shell input keyevent 26
Packages & Performance
The android debug bridge can also return a list of the installed packages installed on the connected device.
adb shell pm list packages -f
To see the CPU usage of the processes running on the device the following command can be used.
adb shell dumpsys cpuinfo
Since the Android Debug Bridge shell is essentially just executing shell commands on the device. You can run a lot of common UNIX commands using it.
Capture a Screenshot
Still not impressed? You can export a screen shot from a device to the current directory if your using Linux.
adb shell screencap -p | perl -pe ‘s/\x0D\x0A/\x0A/g’ > screen.png
This feature is pretty handy when taking screen shots for use in the Google Play store. As it saves taking the screen shot manually and then transferring to a computer for use with the device art generator.
Record a Screencast
On devices running Android Kit Kat (4.4+) and above we can even take things a step further and record a screen-cast from the device! This function is extremely useful for creating promotional videos and tutorials for an application.
To get started simply execute:
adb shell screenrecord /sdcard/example.mp4 –time-limit 5
This will record 5 seconds of video from the device and save to the file example.mp4 in /sdcard/. Using adb we can now pull the video off the device to the current directory on the computer.
adb pull /sdcard/example.mp4
The video file can then be deleted on the device by using adb shell with the rm command.
adb shell “rm /sdcard/example.mp4”
Some other options available for use with the screen recording functionality are:
–size The dimensions of the recorded video, by default this will mimic the display resolution of the device. Using this feature to make low res videos in conjunction the “show touches” option enabled in the developer settings on the device for super helpful bug reports.
–bit-rate The bit rate of the video in bits per second (bps). When not specified the default video bit rate is 4Mbps.
–time-limit The length of the video in time to record in seconds. The maximum length video that can be recorded is 3 minutes.
–verbose By default the screen recording process will not display any information when recording. To see any information output by the process in the terminal you need to use this option.
–rotate Rotates the screen 90 degrees.
WARNING: At the time of writing the documentation for the Android Debug Bridge have the rotate function marked as experimental. So you mileage may vary with this feature.
Related Reading:
Google Documentation for the Android Debug Bridge