MonkeyDevice

 分类:Android, Java 阅读 (1,384)  Add comments
1月 302018
 
转载请注明原文地址:http://bcoder.com/java/monkeydevice

  MonkeyDevice用于控制安卓设备或者安卓模拟器,发送UI事件、发送广播、获取设备信息、安装删除应用和运行应用等。

  一般情况下使用MonkeyRunner.waitForConnection()可获取此类的实例,如下:

  下面是MonkeyDevice提供的一些方法列表:

Methods 描述 描述
void broadcastIntent (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, iterable flags)

Broadcasts an Intent to this device, as if the Intent were coming from an application.

描述
void drag (tuple start, tuple end, float duration, integer steps)

Simulates a drag gesture (touch, hold, and move) on this device’s screen.

描述
object getProperty (string key)

Given the name of a system environment variable, returns its value for this device. The available variable names are listed in the detailed description of this method.

描述
object getSystemProperty (string key)

. The API equivalent of adb shell getprop <key>. This is provided for use by platform developers.

描述
void installPackage (string path)

Installs the Android application or test package contained in packageFile onto this device. If the application or test package is already installed, it is replaced.

描述
dictionary instrument (string className, dictionary args)

Runs the specified component under Android instrumentation, and returns the results in a dictionary whose exact format is dictated by the component being run. The component must already be present on this device.

描述
void press (string name, dictionary type)

Sends the key event specified by type to the key specified by keycode.

描述
void reboot (string into)

Reboots this device into the bootloader specified by bootloadType.

void removePackage (string package)

Deletes the specified package from this device, including its data and cache.

描述
object shell (string cmd)

Executes an adb shell command and returns the result, if any.

描述
void startActivity (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, flags)

Starts an Activity on this device by sending an Intent constructed from the supplied arguments.

描述
MonkeyImage takeSnapshot()

Captures the entire screen buffer of this device, yielding a MonkeyImage object containing a screen capture of the current display.
描述
void touch (integer x, integer y, integer type)

Sends a touch event specified by type to the screen location specified by x and y.

描述
void type (string message)

Sends the characters contained in message to this device, as if they had been typed on the device’s keyboard. This is equivalent to callingpress() for each keycode in message using the key event type DOWN_AND_UP.

描述
void wake ()

Wakes the screen of this device.

描述
打赏