MonkeyDevice是
用来控制
Android设备
或模拟器,
发送
UI事件
的
方法
,
检索信息
,
安装和
删除应用程序,
并可以运行应用程序
。
通常 , 不必使用newdevice = MonkeyDevice()来 创建 MonkeyDevice 的 一个 实例 。 相反的经常 使用 MonkeyRunner.waitForConnection ()来创建 一个新的MonkeyDevice对象 。
通常 , 不必使用newdevice = MonkeyDevice()来 创建 MonkeyDevice 的 一个 实例 。 相反的经常 使用 MonkeyRunner.waitForConnection ()来创建 一个新的MonkeyDevice对象 。
MonkeyDevice的常用方法:
Summary
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
string | DOWN | Use this with the type argument ofpress() ortouch() to send a DOWN event. | |||||||||
string | UP | Use this with the type argument ofpress() ortouch() to send an UP event. | |||||||||
string | DOWN_AND_UP | Use this with the type argument ofpress() ortouch() to send a DOWN event immediately followed by an UP event. |
Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#broadcastIntent" target="_blank">broadcastIntent</a></span> (<em>string</em> uri,<em>string</em> action, <em>string</em> data, <em>string</em> mimetype,<em>iterable</em> categories <em>dictionary</em> extras,<em>component</em> component, <em>iterable</em> flags) </nobr>
Broadcasts an Intent to this device, as if the Intent were coming from an application.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#drag" target="_blank">drag</a></span> (<em>tuple</em> start,<em>tuple</em> end, <em>float</em> duration, <em>integer</em> steps)</nobr>
Simulates a drag gesture (touch, hold, and move) on this device's screen.
| ||||||||||
<nobr><em>object</em></nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#getProperty" target="_blank">getProperty</a></span> (<em>string</em> key)</nobr>
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.
| ||||||||||
<nobr><em>object</em></nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#getSystemProperty" target="_blank">getSystemProperty</a></span> (<em>string</em> key)</nobr>
. The API equivalent of
adb shell getprop <key>. This is provided for use by platform developers.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#installPackage" target="_blank">installPackage</a></span> (<em>string</em> path)</nobr>
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.
| ||||||||||
<nobr><em>dictionary</em></nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#instrument" target="_blank">instrument</a></span> (<em>string</em> className,<em>dictionary</em> args) </nobr>
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.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#press" target="_blank">press</a></span> (<em>string</em> name,<em>dictionary</em> type) </nobr>
Sends the key event specified by type to the key specified by keycode.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#reboot" target="_blank">reboot</a></span> (<em>string</em> into)</nobr>
Reboots this device into the bootloader specified by bootloadType.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#removePackage" target="_blank">removePackage</a></span> (<em>string</em> package)</nobr>
Deletes the specified package from this device, including its data and cache.
| ||||||||||
<nobr><em>object</em></nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#shell" target="_blank">shell</a></span> (<em>string</em> cmd)</nobr>
Executes an
adb shell command and returns the result, if any.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#startActivity" target="_blank">startActivity</a></span> (<em>string</em> uri,<em>string</em> action, <em>string</em> data, <em>string</em> mimetype,<em>iterable</em> categories <em>dictionary</em> extras,<em>component</em> component, <em>flags</em>) </nobr>
Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
| ||||||||||
<nobr><code><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyImage.html" target="_blank"> MonkeyImage</a></code></nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#takeSnapshot" target="_blank">takeSnapshot</a>()</span></nobr>
Captures the entire screen buffer of this device, yielding a
MonkeyImage object containing a screen capture of the current display.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#touch" target="_blank">touch</a></span> (<em>integer</em> x,<em>integer</em> y, <em>integer</em> type) </nobr>
Sends a touch event specified by type to the screen location specified by x and y.
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#touch" target="_blank">type</a></span> (<em>string</em> message)</nobr>
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 in
message using the key event type
DOWN_AND_UP .
| ||||||||||
<nobr> void </nobr> | <nobr><span class="sympad"><a href="http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html#touch" target="_blank">wake</a></span> ()</nobr>
Wakes the screen of this device.
|
http://www.devdiv.com/android/docs/guide/developing/tools/MonkeyDevice.html
/**
* @author 张兴业
* 邮箱:xy-zhang@163.com
* qq:363302850
*
*/