gpt4 book ai didi

android - 如何在已安装的 .apk 上运行 monkeyrunner

转载 作者:太空狗 更新时间:2023-10-29 15:36:40 25 4
gpt4 key购买 nike

我正在尝试在已通过 monkeyrunner 安装的应用程序上运行一些命令。我编辑了 d.android.com 上列出的示例代码并将其更改为:

# 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 但它没有打开我的应用程序,但它似乎在当前应用程序上运行命令。有什么想法吗?

最佳答案

您应该将 runComponent 中的 Activity 指定为

runComponent = package + "/" + activity

获取可启动 Activity 的名称:

$ aapt dump badging <name>.apk | grep launchable-activity

关于android - 如何在已安装的 .apk 上运行 monkeyrunner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15579328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com