我試圖在已經通過monkeyrunner安裝的應用程序上運行一些命令。我已經編輯在d.android.com列出的示例代碼和我改成了這樣:如何在已安裝的.apk上運行monkeyrunner
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
device.installPackage('myproject/bin/MyApplication.apk')
# sets a variable with the package's internal name
package = 'com.example.myTestApp'
# sets a variable with the name of an Activity in the package
# activity = 'com.example.android.myapplication.MainActivity'
# sets the name of the component to start
runComponent = package
# Runs the component
device.startActivity(component=runComponent)
# Presses the Menu button
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)
# Takes a screenshot
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('myproject/shot1.png','png')
正如你所看到的,我改變了代碼(希望)開放com.example.myTestApp
但它不會打開我的應用程序,但它似乎在當前應用程序上運行命令。有任何想法嗎?
如果我只知道包,而不是活動? – EGHDK 2013-03-22 20:44:54
例如,我可以通過從play.google.com中的URL中獲取軟件包名稱來查找手機上另一個應用程序的軟件包名稱。 – EGHDK 2013-03-22 20:46:34
也許你可以檢查logcat消息,試圖打開你的應用程序時顯示的內容。檢查日誌類似「顯示」..我已經看到設置應用程序和一些其他應用程序的情況下的活動名稱。 – Rilwan 2013-03-23 10:42:50