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
Related
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'm pulling my hair out over this; the instructions seemed so simple, yet they just don't work.
Here's the manifest activity intent code:
<activity
android:theme="#style/Theme.Buhzyellowtoplighttabs"
android:name="com.blah.package"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize|stateHidden"
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="http" android:host="www.buhz.com" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So you would think that when I run the app on my phone, go to my browser and go to www.buhz.com it should give me a option to launch the app, right?
As far as I'm aware, this will only work when you click a link to the site, not when you type the URL in.
On the off-chance you're reading this on the Android device your testing on, here is a link for you
Here is the approach that worked for me
The androidmanifest file content is as follows:
<activity
android:name=".SecondActivity"
android:label="#string/title_activity_second">
<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:host="www.example.com"
android:pathPrefix="/roses"
android:scheme="http" />
</intent-filter>
</activity>
The command entered in terminal is as follows :
./adb shell am start -a android.intent.action.VIEW -d "http://www.example.com/roses" com.example.irfan.helloworld
Note:
If your operating system is Windows you can remove the first "./" in the above command.
Result:
It opened the "Second Activity" of my app automatically.
Hope it helps :)
For me:
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.example
didn't work.
Adding category solved it:
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://www.example.com/gizmos"
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).
This is my code. I have read other's post about this issue. They said their code worked very well.
And my code almost the same as theirs. Why doesn't it work in my test. my device is Samsung I9300.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.haibin.androidtest.MainActivity"
android:label="#string/app_name"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="haibintest"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
ps: I using "adb -d shell am start -d haibintest:// -a android.intent.action.VIEW" on command line and it launch susccessfully, while use the url in the brower does't work.
ps2: I test it in opera and it work very well , so i know it will not work in some browers and devices.
To use url scheme inside adb you can use the following command line:
adb shell 'am start "intent:#Intent;scheme=yourscheme://yoururl?param1=value1;end"'
Or you can even do it with QrCodes:
Go to ZXing and generate a url of this format:
yourscheme://yoururl?param1=value1
Then scan it with a QrCode app like BarcodeScanner
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