How can I make a Java app using the Monkeyrunner API?

Matt R. Johnson picture Matt R. Johnson · Jul 13, 2011 · Viewed 8.5k times · Source

The Android SDK has an API for sending commands to the phone called Monkeyrunner. It appears to be a Python API. Is there anyway I can use it in a Java application?

Answer

Harkish picture Harkish · Jul 30, 2011

Well I have been trying to do this, here is what I found (Thanks to google and some help from members on the internet)

Here is a little Java program that uses monkeyrunner to print the name of the device

import com.android.monkeyrunner.MonkeyDevice;
import com.android.monkeyrunner.adb.AdbBackend;

public class Monk {

 public static void main(String[] args) {
    // TODO code application logic here
    Monk monk=new Monk();
    monk.demo();
 }
 public void demo()
 {
    AdbBackend ab = new AdbBackend();
    MonkeyDevice device = ab.waitForConnection();
    //Print Device Name       
    System.out.println(device.getProperty("build.model"));
    device.dispose();
 }

}

For the above code too work, I needed to include the following jars monkeyrunner, ddmlib, jython, guavalib, sdklib.