Android自动化工具Monkeyrunner使用(四)

本章将详细解析Monkeyrunner API中用于获取系统属性的方法,包括如何通过系统环境变量名获取设备的特定属性,如宽度、高度、密度等,并提供了实际应用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     本章开始介绍下MonkeyrunnerAPI, 以便了解其具体的使用。

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 getProperty (string key)

Given the name of a system environment variable, returns its value for this device.

Arguments
keyThe name of the system environment variable. The available variable names are listed in Table 1. Property variable names at the end of this topic.
Returns
  • The value of the variable. The data format varies according to the variable requested.

E.g. 获取当前设备的width

device.startActivity(component=runComponent)

width = device.getProperty('display.width')

pring width



以下为key的具体内容:

Property GroupPropertyDescriptionNotes
buildboardCode name for the device's system boardSee Build
brandThe carrier or provider for which the OS is customized.
deviceThe device design name.
fingerprintA unique identifier for the currently-running build.
host 
IDA changelist number or label.
modelThe end-user-visible name for the device.
productThe overall product name.
tagsComma-separated tags that describe the build, such as "unsigned" and "debug".
typeThe build type, such as "user" or "eng".
user 
CPU_ABIThe name of the native code instruction set, in the form CPU type plus ABI convention.
manufacturerThe product/hardware manufacturer.
version.incrementalThe internal code used by the source control system to represent this version of the software.
version.releaseThe user-visible name of this version of the software.
version.sdkThe user-visible SDK version associated with this version of the OS.
version.codenameThe current development codename, or "REL" if this version of the software has been released.
displaywidthThe device's display width in pixels.See DisplayMetrics for details.
heightThe device's display height in pixels.
densityThe 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 density for more details.

am.currentpackageThe Android package name of the currently running package.The am.current keys return information about the currently-running Activity.
actionThe current activity's action. This has the same format as the name attribute of the action element in a package manifest.
comp.classThe class name of the component that started the current Activity. See comp.package for more details.
comp.packageThe 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.
dataThe data (if any) contained in the Intent that started the current Activity.
categoriesThe categories specified by the Intent that started the current Activity.
clockrealtimeThe number of milliseconds since the device rebooted, including deep-sleep time.See SystemClock for more information.
uptimeThe number of milliseconds since the device rebooted, not including deep-sleep time
milliscurrent time since the UNIX epoch, in milliseconds.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值