monkeyrunner要学习,必须有的是启动了avd,如果不知道怎么启动avd,请看我上一篇的内容,本文主要讲述我在模拟器上使用monkeyrunner做的第一个测试。 1.终端打开monkeyrunner的路径:/usr/java/sdk/.../tools
2../monkeyrunner
3.from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
4.device=MonkeyRunner.waitForConnection() 连接avd和monkeyrunner
5.device.installPackage('.../***.apk') 安装某个app到模拟器,true说明安装成功 6.device.startActivity("packageName/startActivity") how to get packageName and startActivity
2. 获取packageName, 我把Apidemos.apk安装到手机/模拟器上,然后打开,通过以下代码可以实现: import android
import pprint
droid=android.Android()
pacs=droid.getRunningPackages()
pprint.pprint(pacs.result)
这样就可以获取packageName了
3.获取startActivity 通过以下代码获取startActivity,代码如下: import android
import pprint
droid=android.Android()
apps=droid.getLaunchableApplications()
pprint.pprint(apps.result)
这样就可以获取到startActivity了。
2.获取packagename and activity的第二个方法 下载 re-sign.jar,配置号java和android的环境变量, 终端输入命令:java -jar re-sign.jar 等一会resign successfull,packagename and activity就popup出来了。
在使用该工具的时候需要用到sdk/tool/zipalign, 如果你的sdk中没有,请去网上自行下载,如果你用的ubuntu系统,需要把exe后缀去掉,同时修改一下zipalign的权限, chmod一下即可。
3.获取packagename and activity的第三个方法 在sdk中有一个工具可以直接获得packagename and activity name,这个工具叫aapt path:sdk/builds-tools/bin/aapt 在终端输入:./aapt dump badging '/home/rusername/下载/ApiDemos.apk' 结果如图所示:
package: name='api.demos' versionCode='4' versionName='1.6' platformBuildVersionName=''
sdkVersion:'4'
uses-permission: name='android.permission.READ_CONTACTS'
uses-permission: name='android.permission.WRITE_CONTACTS'
uses-permission: name='android.permission.CAMERA'
uses-permission: name='android.permission.VIBRATE'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.INTERNET'
application-label:'API Demos'
application-icon-120:'res/drawable/app_sample_code.png'
application-icon-160:'res/drawable/app_sample_code.png'
application-icon-240:'res/drawable/app_sample_code.png'
application-icon-65535:'res/drawable/app_sample_code.png'
application: label='API Demos' icon='res/drawable/app_sample_code.png'
launchable-activity: name='com.example.android.apis.ApiDemos' label='' icon=''
uses-permission: name='android.permission.READ_CALL_LOG'
uses-implied-permission: name='android.permission.READ_CALL_LOG' reason='targetSdkVersion < 16 and requested READ_CONTACTS'
uses-permission: name='android.permission.WRITE_CALL_LOG'
uses-implied-permission: name='android.permission.WRITE_CALL_LOG' reason='targetSdkVersion < 16 and requested WRITE_CONTACTS'
feature-group: label=''
uses-feature: name='android.hardware.camera'
uses-implied-feature: name='android.hardware.camera' reason='requested android.permission.CAMERA permission'
uses-feature: name='android.hardware.location'
uses-implied-feature: name='android.hardware.location' reason='requested android.permission.ACCESS_COARSE_LOCATION permission'
uses-feature: name='android.hardware.location.network'
uses-implied-feature: name='android.hardware.location.network' reason='requested android.permission.ACCESS_COARSE_LOCATION permission'
uses-feature: name='android.hardware.screen.landscape'
uses-implied-feature: name='android.hardware.screen.landscape' reason='one or more activities have specified a landscape orientation'
uses-feature: name='android.hardware.touchscreen'
uses-implied-feature: name='android.hardware.touchscreen' reason='default feature for all apps'
provides-component:'app-widget'
/////////////// 颜色标记的分别位package name and activity name.
4.获取packagename and activity name的第四种方法: 使用sdk中自带的工具hierarchy,话说这个工具及其的好用啥,打开目录:sdk/tools/ 终端打开到tools目录,然后敲入命令:./hierarchy, 即会弹出窗口 hierarchy viewer. 可以在里面查看到package name and activity name
details plz see:http://www.xuxu1988.com/2015/05/20/android-get-activity/
|