Android:在Monkey中使用类别

tjb*_*tjb 11 android

如何使用猴子工具的类别选项?

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

   <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>
Run Code Online (Sandbox Code Playgroud)

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

adb shell monkey -p my.full.package.path -vvv 3
Run Code Online (Sandbox Code Playgroud)

它工作得很好.

但这不起作用:

adb shell monkey -p my.full.package.path -c intent.CATEGORY_LAUNCHER -vvv 3
Run Code Online (Sandbox Code Playgroud)

并产生以下输出:

: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.
Run Code Online (Sandbox Code Playgroud)

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

    :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.
Run Code Online (Sandbox Code Playgroud)

如何指定类别

Jam*_*war 9

你真的很亲密 这对我有用:

adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -vvv 3
Run Code Online (Sandbox Code Playgroud)

我认为问题是你需要包括Launcher,因为如果你没有猴子无法启动该程序.不要担心你可以放一个-c param.例如,您可以这样做:

adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -vvv 3
Run Code Online (Sandbox Code Playgroud)

它应该工作.