How do I use the categories option of the monkey tool?
The relevant portion of my manifest file looks like this:
<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>
I run the application on my phone to make sure it is working then I enter this at the command line:
adb shell monkey -p my.full.package.path -vvv 3
It works just fine.
But this doesn't work:
adb shell monkey -p my.full.package.path -c intent.CATEGORY_LAUNCHER -vvv 3
and yields the following output:
: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.
And trying some variants also didn't work:
: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.
How do I specify categories
You're really close. This worked for me:
adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -vvv 3
I think the problem is that you need to include the Launcher too, because if you don't monkey can't start the program. Don't worry you can put more then one -c param. For example you could do:
adb shell monkey -p com.JamesBecwar.test -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -vvv 3
and it should work.
As far as I can understand by looking at the Monkey source code is that the -c argument stands for "main-category", it will only work in combination with a main-action. That the -c/main-categories criteria will only work when the monkey tries to start the app with "Implicit Intents" and not "Explicit Intents" within the app.
<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
Related
I know it's a duplicated question but any solution I tried not resolved the problem.
The real question is there's a way to launch the app when the activity alias is enabled? I mean, my app has a feature to change the icon launcher for certain users and I want to build the app and launch it when the icon has changed, so the activity alias is enabled.
here's the error:
Error while executing: am start -n "SplashScreenActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=SplashScreenActivity }
Error type 3
Error: Activity class {SplashScreenActivity} does not exist.
Error while Launching activity
Failed to launch an application on all devices
Here's my manifest:
<activity
android:name="SplashScreenActivity"
android:configChanges="orientation|keyboardHidden"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name="SplashScreenActivityAlias"
android:icon="#mipmap/ic_launcher_prime"
android:label="#string/app_name_app"
android:enabled="false"
android:targetActivity="SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
I saw some resolutions that I need uninstall the app but I want to just build and launch as the app normally do.
You haven't fully qualified the component, so it doesn't know where to find it. You need to provide the package name for your Activity, like this:
am start -n "my.package.name/.SplashScreenActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Note: I have used "my.package.name" for the package. You need to replace that with your app's package name, as you have it in the manifest. Also note the "." (period, dot) character after the "/" (slash) character before SplashScreenActivity.
I order to test <action android:name="android.intent.action.BOOT_COMPLETED" />, I hope to simulate restart action in Android Emulator.
How can I do? Thanks!
And more
If I hope to test whether setPersisted(true) work after I restart phone in Android Emulator, how can I do?
val jobInfo = JobInfo.Builder(mContext.getInteger(R.integer.JobID), ComponentName(mContext, RestoreService::class.java))
.setPeriodic(interval)
.setPersisted(true)
.build()
Added:
The following is myAndroidManifest.xml file.
Which one is correct between Code A and Code B by your answer?
or both Code A and Code are wrong?
Code A
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/ui.UIApp
Code B
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/bll.BootReceiver
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.dodata.mirror">
<application
android:name="ui.UIApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="ui.UIMain" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ui.UIAbout">
<intent-filter>
<action android:name="ui.UIAbout" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="bll.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
In general this ADB command will send any broadcast and you can catch with debugger:
adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME
Here is general boot broadcast sending:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name
Based on your manifest, first add to manifest receiver enabled and exported this :
<receiver
android:name="bll.BootReceiver"
android:enabled="true"
android:exported="true">
Example with your classes and manifest, ADB call should look like this:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n info.dodata.mirror/bll.BootReceiver
I have an activity which display celebrity and some information.
Declaration in manifest :
<activity
android:name=".CelebrityActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_celebrities"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="some_scheme" />
</intent-filter>
</activity>
Following this guide :
For example, the command below tries to view a target app activity that is associated with the specified URI.
$ adb shell am start
-W -a android.intent.action.VIEW
-d "example://gizmos" com.example.android
My problem it was when i execute adb command(which you see above) it recreates my Activity always, even activity is launched.
I try to add launchMode:singleInstance flag, but... no changes. Activity also recreates.
So my question is how to handle result in existing Activity?
I believe you need to use
adb shell am broadcast -a "android.intent.action.VIEW" -d "some_scheme://"
instead of adb shell am start. Links are handled as a broadcast by the android framework.
I am trying to get the android ui monkey running for the first time and am having some problems.
I have run adb shell monkey -v 100 which works fine, but obviously only on the system UI not on my own application.
I then try
adb shell monkey -p com.rbennett485.dawnoftheveg -v 100
and get the output
:Monkey: seed=1406692871132 count=100
:AllowPackage: com.rbennett485.dawnoftheveg
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
** No activities found to run, monkey aborted.
The relevant section of my manifest is
<activity
android:name="com.rbennett485.dawnoftheveg.DawnOfTheVeg"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity>
Any ideas? I know a lot has been asked about this error before, but it mostly seems to be from not using the full package name - am I using the correct package name here?
Turned out the package my main activity was in had a different name to the package that was defined in my manifest. By using the manifest package name instead it worked fine
I have the following in my AndroidManifest.xml (I just added a second activity to the default project):
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.com.testapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.com.testapp.TestActivity"
android:label="#string/title_activity_test" >
<intent-filter>
<action android:name="com.testapp.action.TEST_ACTION" />
</intent-filter>
</activity>
I want to launch the TestActivity using adb command. I tried:
./adb shell am start -a com.testapp.action.TEST_ACTION
But it gives the error:
Error: Activity not started, unable to resolve Intent { act=com.testapp.action.TEST_ACTION flg=0x10000000 }
Can someone please explain why I am getting this error and how to resolve it?
Edit :
Can anyone tell a way to just use action to launch the 'TestActivity'.
I think you should add the code below into your intentfilter
<category android:name="android.intent.category.DEFAULT"/>
try using:
adb shell "am start -n com.example.com.testapp/.TestActivity -a com.testapp.action.TEST_ACTION"
or
adb shell "am start com.example.com.testapp -a com.testapp.action.TEST_ACTION"
hope that works.
Try adb shell am start -n com.mypackage.name/com.mypackage.name.TEST_ACTION (replace the package names and activity names as needed)
Take a look at this solution.
To expand on what 陈薛星 wrote, in the "Android developer guide on Intent Filters" under "Category Test", it states
Note: Android automatically applies the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult(). If you want your activity to receive implicit intents, it must include a category for "android.intent.category.DEFAULT" in its intent filters, as shown in the previous example.
So you need to add
<category android:name="android.intent.category.DEFAULT"/> to your intent filter.
This will match an implicit intent. (Several other answers show how to target a class explicity).