monkeyrunner要學習,必須有的是啓動了avd,若是不知道怎麼啓動avd,請看我上一篇的內容,本文主要講述我在模擬器上使用monkeyrunner作的第一個測試。 html
1.終端打開monkeyrunner的路徑:/usr/java/sdk/.../tools java
2../monkeyrunner android
3.from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage ubuntu
4.device=MonkeyRunner.waitForConnection() api
鏈接avd和monkeyrunner app
5.device.installPackage('.../***.apk') ide
安裝某個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了。
http://blog.csdn.net/robinzhou/article/details/6851902
http://blog.sina.com.cn/s/blog_6abda9bc01015zoc.html
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/