Command-Line Android Screen Capture with Groovy
I’m writing a chapter about jQuery Mobile for a Manning book, tentatively titled “Mobile Web Apps In Practice”.
I need to get some good, high-quality screen captures for illustrations for the chapter. I read a few articles about how to do a screen capture on an Android device using the ddms tool from the Android sdk, and that worked fine (see, for example, http://forum.gtvhacker.com/gtv-guides/topic59.html if you’re interested). But I figured that there had to be an easier way.
I found Java code for use of the ddmlib library for working with the Android SDK to do a screen capture at https://github.com/roman10/roman10-android-tutorial/blob/master/screenshot/src/com/android/screenshot/Screenshot.java.
This was good, but I both wanted an easy one-liner shell script, and to be able to customize the operation easily. So, being a fan of Groovy, I turned the Java code into a Groovy script, and dumped the source code for ddmlib in favor of a Grapes reference to the library in the central Maven repo.
I set up the groovy script to run as a shell script, and got rid of the .groovy extension.
Now I have a nice command-line way to do Android hardware screen captures.
The script is at https://github.com/rfreedman/android-screencapture. Feel free to fork and hack!