page.title=MonkeyDevice parent.title=monkeyrunner parent.link=index.html @jd:body
A monkeyrunner class that represents a device or emulator accessible by the workstation running
monkeyrunner
.
This class is used to control an Android device or emulator. The methods send UI events, retrieve information, install and remove applications, and run applications.
You normally do not have to create an instance of MonkeyDevice
. Instead, you
use
MonkeyRunner.waitForConnection()
to create a new object from a connection to a device or
emulator. For example, instead of
using:
newdevice = MonkeyDevice()
you would use:
newdevice = MonkeyRunner.waitForConnection()
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
string | DOWN |
Use this with the type argument of
press() or touch()
to send a DOWN event.
|
|||||||||
string | UP |
Use this with the type argument of
press() or touch()
to send an UP event.
|
|||||||||
string | DOWN_AND_UP |
Use this with the type argument of
press() or touch()
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 in message
using the key event type DOWN_AND_UP .
|
||||||||||
|
Wakes the screen of this device.
|
Broadcasts an Intent to this device, as if the Intent were coming from an application. See {@link android.content.Intent Intent} for more information about the arguments.
uri | The URI for the Intent. (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}). |
---|---|
action | The action for this Intent (see {@link android.content.Intent#setAction(java.lang.String) Intent.setAction()}). |
data | The data URI for this Intent (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}). |
mimetype | The MIME type for the Intent (see {@link android.content.Intent#setType(java.lang.String) Intent.setType()}). |
categories | An iterable data structure containing strings that define categories for this Intent (see {@link android.content.Intent#addCategory(java.lang.String) Intent.addCategory()}). |
extras |
A dictionary of extra data for this Intent
(see {@link android.content.Intent#putExtra(java.lang.String,java.lang.String)
Intent.putExtra()}
for an example).
The key for each dictionary item should be a string. The item's value can be any simple or structured data type. |
component | The component for this Intent (see {@link android.content.ComponentName}). Using this argument will direct the Intent to a specific class within a specific Android package. |
flags | An iterable data structure containing flags that control how the Intent is handled (see {@link android.content.Intent#setFlags(int) Intent.setFlags()}). |
Simulates a drag gesture (touch, hold, and move) on this device's screen.
start | The starting point of the drag gesture, in the form of a tuple (x,y) where x and y are integers. |
---|---|
end | The end point of the drag gesture, in the form of a tuple (x,y) where x and y are integers. |
duration | The duration of the drag gesture in seconds. The default is 1.0 seconds. |
steps | The number of steps to take when interpolating points. The default is 10. |
Given the name of a system environment variable, returns its value for this device.
key | The name of the system environment variable. The available variable names are listed in Table 1. Property variable names at the end of this topic. |
---|
Synonym for getProperty()
.
key | The name of the system environment variable. The available variable names are listed in Table 1. Property Variable Names. |
---|
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.
path |
The fully-qualified path and filename of the .apk file to install.
|
---|
Runs the specified component with 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.
Use this method to start a test case that uses one of Android's test case classes. See Testing Fundamentals to learn more about unit testing with the Android testing framework.
className |
The name of an Android component that is already installed on this device, in the
standard form packagename/classname, where packagename is the
Android package name of a .apk file on this device, and
classname is the class name of an Android component (Activity,
ContentProvider, Service, or BroadcastReceiver) in that file. Both
packagename and classname must be fully qualified. See
{@link android.content.ComponentName} for more details.
|
---|---|
args | A dictionary containing flags and their values. These are passed to the component as it is started. If the flag does not take a value, set its dictionary value to an empty string. |
A dictionary containing the component's output. The contents of the dictionary are defined by the component itself.
If you use {@link android.test.InstrumentationTestRunner} as the class name in
the componentName argument, then the result dictionary contains
the single key "stream". The value of "stream" is a string containing
the test output, as if InstrumentationTestRunner
was run from the
command line. The format of this output is described in
Testing in Other IDEs.
Sends the key event specified by type
to the key specified by
keycode
.
name | The name of the keycode to send. See {@link android.view.KeyEvent} for a list of keycode names. Use the keycode name, not its integer value. |
---|---|
type |
The type of key event to send. The allowed values are
DOWN , UP , and
DOWN_AND_UP .
|
Reboots this device into the bootloader specified by bootloadType
.
into | The type of bootloader to reboot into. The allowed values are "bootloader", "recovery", or "None". |
---|
Deletes the specified package from this device, including its data and cache.
package |
The Android package name of an .apk file on this device.
|
---|
Executes an adb
shell command and returns the result, if any.
cmd |
The command to execute in the adb shell. The form of these commands is
described in the topic Android
Debug Bridge.
|
---|
Starts an Activity on this device by sending an Intent constructed from the supplied arguments.
uri | The URI for the Intent. (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}). |
---|---|
action | The action for the Intent (see {@link android.content.Intent#setAction(java.lang.String) Intent.setAction()}). |
data | The data URI for the Intent (see {@link android.content.Intent#setData(android.net.Uri) Intent.setData()}). |
mimetype | The MIME type for the Intent (see {@link android.content.Intent#setType(java.lang.String) Intent.setType()}). |
categories | An iterable data structure containing strings that define categories for the Intent (see {@link android.content.Intent#addCategory(java.lang.String) Intent.addCategory()}). |
extras |
A dictionary of extra data for the Intent
(see
{@link android.content.Intent#putExtra(java.lang.String,java.lang.String)
Intent.putExtra()}
for an example).
The key for each dictionary item should be a string. The item's value can be any simple or structured data type. |
component | The component for the Intent (see {@link android.content.ComponentName}). Using this argument will direct the Intent to a specific class within a specific Android package. |
flags | An iterable data structure containing flags that control how the Intent is handled (see {@link android.content.Intent#setFlags(int) Intent.setFlags()}). |
MonkeyImage
takeSnapshot
()
Captures the entire screen buffer of this device, yielding a screen capture of the current display.
Sends a touch event specified by type to the screen location specified by x and y.
x | The horizontal position of the touch in actual device pixels, starting from the left of the screen in its current orientation. |
---|---|
y | The vertical position of the touch in actual device pixels, starting from the top of the screen in its current orientation. |
type |
The type of key event to send. The allowed values are
DOWN , UP , and
DOWN_AND_UP .
|
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
.
message | A string containing the characters to send. |
---|
Wakes the screen of this device.
Property Group | Property | Description | Notes |
---|---|---|---|
build |
board |
Code name for the device's system board | See {@link android.os.Build} |
brand |
The carrier or provider for which the OS is customized. | ||
device |
The device design name. | ||
fingerprint |
A unique identifier for the currently-running build. | ||
host |
|||
ID |
A changelist number or label. | ||
model |
The end-user-visible name for the device. | ||
product |
The overall product name. | ||
tags |
Comma-separated tags that describe the build, such as "unsigned" and "debug". | ||
type |
The build type, such as "user" or "eng". | ||
user |
|||
CPU_ABI |
The name of the native code instruction set, in the form CPU type plus ABI convention. | ||
manufacturer |
The product/hardware manufacturer. | ||
version.incremental |
The internal code used by the source control system to represent this version of the software. | ||
version.release |
The user-visible name of this version of the software. | ||
version.sdk |
The user-visible SDK version associated with this version of the OS. | ||
version.codename |
The current development codename, or "REL" if this version of the software has been released. | ||
display |
width |
The device's display width in pixels. | See {@link android.util.DisplayMetrics} for details. |
height |
The device's display height in pixels. | ||
density |
The logical density of the display. This is a factor that scales
DIP (Density-Independent Pixel) units to the device's resolution. DIP is adjusted so
that 1 DIP is equivalent to one pixel on a 160 pixel-per-inch display. For example,
on a 160-dpi screen, density = 1.0, while on a 120-dpi screen, density = .75.
The value does not exactly follow the real screen size, but is adjusted to conform to large changes in the display DPI. See {@link android.util.DisplayMetrics#density} for more details. |
||
am.current |
package |
The Android package name of the currently running package. |
The am.current keys return information about the currently-running
Activity.
|
action |
The current activity's action. This has the same format as the name
attribute of the action element in a package manifest.
|
||
comp.class |
The class name of the component that started the current Activity. See
comp.package for more details. |
||
comp.package |
The package name of the component that started the current Activity. A component is specified by a package name and the name of class that the package contains. | ||
data |
The data (if any) contained in the Intent that started the current Activity. | ||
categories |
The categories specified by the Intent that started the current Activity. | ||
clock |
realtime |
The number of milliseconds since the device rebooted, including deep-sleep time. | See {@link android.os.SystemClock} for more information. |
uptime |
The number of milliseconds since the device rebooted, not including deep-sleep time | ||
millis |
current time since the UNIX epoch, in milliseconds. |