通常,不必使用newdevice = MonkeyDevice()来创建MonkeyDevice的一个实例。相反的经常使用MonkeyRunner.waitForConnection()来创建一个新的MonkeyDevice对象。
MonkeyDevice的常用方法:
Summary
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
string | DOWN | Use this with the type argument of press() ortouch()
to send a DOWN event. |
|||||||||
string | UP | Use this with the type argument of press() ortouch()
to send an UP event. |
|||||||||
string | DOWN_AND_UP | Use this with the type argument of press() ortouch()
to send a DOWN event immediately followed by an UP event. |
Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Broadcasts an Intent to this device, as if the Intent were coming from an application.
|
|||||||||||
Simulates a drag gesture (touch, hold, and move) on this device's screen.
|
|||||||||||
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.
|
|||||||||||
. The API equivalent of
adb shell getprop <key>. This is provided for use by platform developers.
|
|||||||||||
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.
|
|||||||||||
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.
|
|||||||||||
Sends the key event specified by type to the key specified by keycode.
|
|||||||||||
Reboots this device into the bootloader specified by bootloadType.
|
|||||||||||
Deletes the specified package from this device, including its data and cache.
|
|||||||||||
Executes an
adb shell command and returns the result, if any. |
|||||||||||
Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
|
|||||||||||
MonkeyImage |
Captures the entire screen buffer of this device, yielding a
MonkeyImage object
containing a screen capture of the current display. |
||||||||||
Sends a touch event specified by type to the screen location specified by x and y.
|
|||||||||||
Sends the characters contained in message to this device, as if they had been typed on the device's keyboard. This is equivalent to calling
press()
for each keycode inmessage using the key event type
DOWN_AND_UP . |
|||||||||||
Wakes the screen of this device.
|
http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html
/**
* @author 张兴业
* 邮箱:xy-zhang@163.com
* qq:363302850
*
*/