首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:在Monkey中使用类别

Android:在Monkey中使用类别
EN

Stack Overflow用户
提问于 2011-10-29 22:08:21
回答 2查看 7.3K关注 0票数 11

如何使用monkey工具的categories选项?

我的清单文件的相关部分如下所示:

代码语言:javascript
复制
   <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="MyApp" android:debuggable="true" android:allowBackup="false" android:testOnly="false">
        <activity android:name="MyLauncherActivity" android:label="@string/app_name" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="MyMainActivity" android:label="@string/app_name" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="none" />
                <category android:name="android.intent.category.MONKEY" />
            </intent-filter>
        </activity>

我在手机上运行应用程序以确保它正常工作,然后在命令行中输入以下内容:

代码语言:javascript
复制
adb shell monkey -p my.full.package.path -vvv 3

它工作得很好。

但这不起作用:

代码语言:javascript
复制
adb shell monkey -p my.full.package.path -c intent.CATEGORY_LAUNCHER -vvv 3

并产生以下输出:

代码语言:javascript
复制
:Monkey: seed=0 count=3

:AllowPackage: myapp.full.package.path

:IncludeCategory: intent.CATEGORY_LAUNCHER

// Warning: no activities found for category intent.CATEGORY_LAUNCHER

** No activities found to run, monkey aborted.

尝试一些变体也不起作用:

代码语言:javascript
复制
    :Monkey: seed=0 count=3

:AllowPackage: my.full.package.path

:IncludeCategory: CATEGORY_MONKEY

:IncludeCategory: intent.CATEGORY_MONKEY

:IncludeCategory: android.intent.MONKEY

:IncludeCategory: android.intent.category.MONKEY

:IncludeCategory: MONKEY

// Warning: no activities found for category CATEGORY_MONKEY

// Warning: no activities found for category intent.CATEGORY_MONKEY

// Warning: no activities found for category android.intent.MONKEY

// Warning: no activities found for category MONKEY

** No activities found to run, monkey aborted.

如何指定类别

EN

回答 2

Stack Overflow用户

发布于 2011-11-03 23:53:55

你真的很接近了。这对我很有效:

代码语言:javascript
复制
adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -vvv 3

我认为问题是你也需要包括启动程序,因为如果你不这样做,猴子就不能启动程序。不要担心,您可以放置多个-c参数。例如,您可以这样做:

代码语言:javascript
复制
adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -vvv 3

它应该是有效的。

票数 11
EN

Stack Overflow用户

发布于 2018-11-29 18:00:24

据我所知,通过查看Monkey源代码,-c参数代表"main-category",它只能与main-action结合使用。只有当猴子尝试使用应用程序中的“隐式意图”而不是“显式意图”启动应用程序时,-c/main-categories标准才会起作用。

代码语言:javascript
复制
<intent-filter>
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.MONKEY" />
</intent-filter>

https://android.googlesource.com/platform/development/+/master/cmds/monkey/src/com/android/commands/monkey/Monkey.java

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7939402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档