本文共 2001 字,大约阅读时间需要 6 分钟。
import java.util.TreeMap;import com.android.chimpchat.ChimpChat;import com.android.chimpchat.core.IChimpDevice;public class JavaMonkey { private static final String ADB = "/home/eamon/android-sdk/android-sdk-linux_x86/platform-tools/adb"; private static final long TIMEOUT = 5000; private ChimpChat mChimpchat; private IChimpDevice mDevice; /** * Constructor */ public JavaMonkey() { super(); TreeMapoptions = new TreeMap (); options.put("backend", "adb"); options.put("adbLocation", ADB); mChimpchat = ChimpChat.getInstance(options); } /** * Initializes the JavaMonkey. */ private void init() { mDevice = mChimpchat.waitForConnection(TIMEOUT, ".*"); if ( mDevice == null ) { throw new RuntimeException("Couldn't connect."); } mDevice.wake(); } /** * List all properties. */ private void listProperties() { if ( mDevice == null ) { throw new IllegalStateException("init() must be called first."); } mDevice.drag(10, 10, 140, 280, 136, 2); for (String prop: mDevice.getPropertyList()) { System.out.println(prop + ": " + mDevice.getProperty(prop)); } } /** * Terminates this JavaMonkey. */ private void shutdown() { mChimpchat.shutdown(); mDevice = null; } /** * @param args */ public static void main(String[] args) { final JavaMonkey javaMonkey = new JavaMonkey(); javaMonkey.init(); javaMonkey.listProperties(); javaMonkey.shutdown(); }}
转载地址:http://marlo.baihongyu.com/