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).
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 am trying to pass parameters to deep links in Android and that is not working.
I have specified a hostName variable in the app/build.gradle file to distinguish between UAT and production URLs. This hostName variable is referenced in AndroidManifest.xml like so:
<activity
android:name=".ui.MyActivity"
android:theme="#style/MyTheme"
android:configChanges="orientation"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- deep links for home page. -->
<data
android:scheme="https"
android:host="${hostName}"
android:pathPrefix="/login.jsp?signup=true" />
</intent-filter>
</activity>
I am trying to use adb to test for deep links like so:
adb.exe shell am start -W -a android.intent.action.VIEW -d "https://www.mywebsite.co.in/login.jsp?signup=true" com.myapp.ui.MyActivity
The error I get is:
Starting: Intent { act=android.intent.action.VIEW dat=https://www.mywebsite.co.in/... pkg=com.myapp.android.alpha }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=https://www.mywebsite.co.in/... flg=0x10000000 pkg=com.myapp.android.alpha }
I have read through a number of similar questions here on SO and all of them suggest escaping the special characters. But that has not worked in this case.
Any insights on resolving this will be most welcome.
The android:pathPrefix is invalid in your AndroidManifest.xml.
It should only contain the path element, not the query:
android:pathPrefix="/login.jsp"
The query string ?signup=true is not part of the path. You cannot filter on query strings.
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 created a splash screen for my android application. In my AndroidManifest I set the SplashScreen Activity as Launcher and action as MAIN. After that I changed the HomeActivity's intentfilter.
Here is my android manifest file:
<application
android:allowBackup="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreenActivity"
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=".ActivityHome"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.ACTIVITHOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".Receivers.NetworkReceiver"></receiver>
</application>
I have both these activities inside the default package. Now, when I try to test the application in device, I get the following error:
Error while executing: am start -n "com.sdz.myapp/com.sdz.myapp.SplashScreenActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sdz.myapp/.SplashScreenActivity }
Error type 3
Error: Activity class {com.sdz.myapp/com.sdz.myapp.SplashScreenActivity} does not exist.
Error while Launching activity
This is how my project structure looks like:
src
-com.sdz.myapp
----ActivityHome
----SplashScreenActivity
I restarted android studio but still the error is there. I dont know what is causing this.
I ran into this as well. I actually had to uninstall the apk from the device before it would work... which was really odd as the app wasn't showing up on my list of apps on the phone.
Here's what I did:
Opened up command line
Ran 'adb devices' to make sure my device was connected
ran 'adb uninstall ' Replace with "com.whatever.blah"
You should see a message saying it uninstall successfully
Try installing from Android Studio again and it should work
I have no idea how it gets in this weird state. :-/
Please change your android:name value at your activity tag with full name and first clean project . After that try to run your application again
<activity android:name="com.sdz.myapp.SplashScreenActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have this same issue occasionally. The solution was to build the APK (menu "Build > Build APK") and install it manually in the phone. After that the error disappears.
I tried all of the above plus even delete the build folder and still did not work. The solution for me was: On your Android Studio go to File->Sync Project with Gradle Files
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.