Appendix D. monkeyrunner
In this last appendix, we’re going to look at another recent addition to the Android SDK toolset: the monkeyrunner. The material covered here complements what we covered in chapters 13 and 14—testing, instrumentation, and build automation—although the monkeyrunner takes a special role both technically and usage-wise, as you’ll see in a minute.
Not to be confused with the monkey tool (see chapter 13), the monkeyrunner is a scripted and extensible application that allows you to control an emulator or device in a programmatic fashion. Similar to Android’s instrumentation framework, it allows you to steer flow of an application by launching activities and sending input events, but it does so from outside the Android framework, much like a real-world user would. Using monkeyrunner, you can install or uninstall application packages, interact with a device’s command shell, and even capture screenshots of the current screen. Think of monkeyrunner as a remote control for Android.
The monkeyrunner itself is written in Java, is part of the Android SDK, and a shell script to launch it can be found in the ANDROID_HOME/tools folder. It’s a command line application and has no graphical UI. You can run monkeyrunner in two different modes: default or interactive. In default mode, monkeyrunner takes scripted programs as input and executes them: