Screenshots of Emulated Android Devices
Heads up: It takes only a few lines of bash code to take screenshots of emulated Android devices. As I have recently been developing apps with Angular2 and Ionic2 I had the need to create screenshots of the current work-in-progress of the app. The paid version of the Genymotion emulator supports creating screenshots out of the box, but there is an even better way to create them.
The following code snippet captures screenshots in Genymotion, but also applies to capturing screenshots with Android SDK/Studio. The original idea to use the Android Debug Tools
adb to take screenshots traces back to this article.
Simply add an alias
The article notes that the binary output of the
adb tool needs to be post-processed to clean up the line endings. As I am using the Babun Cygwin shell on Windows, the
sed variant to replace the line feeds seemed more appealing than
perl. To be able to easily invoke a command, I added an alias to the
~/.bash_profile as follows:
alias adb_screenshot="adb shell screencap -p | sed 's/\r$//' > /path/to/storage/screenshot_\$(date +%Y%m%d_%H%M%S).png"
To make it more convenient, I added the current date and time to the file name of the screenshot. Now I can navigate the app and create screenshots with just a call to
adb_screenshot from the terminal. The results are then stored in the defined folder and are ready to be shared.