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.
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'm trying to get make a url open the app and to have some data with this url passed into the app, but it doesn't work.
My activity tag in AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"> <-- added this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="fcm.ACTION.HELLO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<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="conv"
android:host="convid"/> <-- so urls of the form 'conv://convid/ will open the app
</intent-filter>
</activity>
And I added to the entry class of the app:
componentDidMount() {
Linking.addEventListener('url', (e) => {
console.log("url", e);
});
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
})
}
But when I open the browser and go to conv://convid nothing is being logged and the app doesn't open.
Of course I opened my app before the browser.
The app will not open if the link is entered into the browser's address bar. It has to be a web page <a/> tag like:
link inside some page. (https://developer.chrome.com/multidevice/android/intents)
As you probably do not have a web page to put tag inside, for your tests you can use adb command. Open the console and write the following line:
adb shell am start -W -a android.intent.action.VIEW -d "YOURHOST://YOURSCEME/" com.YOURAPPNAME
for example in your case it should be something like (change YOURAPPNAME with the name of your app):
adb shell am start -W -a android.intent.action.VIEW -d "convid://conv/" com.YOURAPPNAME
if you are using windows and, and if it says adb command is undefined you need to run the command from platform-toolsfolder inside your SDK folder such as:
Android/Sdk/platform-tools/
I'm trying to enable deep linking so that certain links launch my app.
I read this turotial https://developer.android.com/training/app-indexing/deep-linking.html and following it pretty close but when I try to test it by using adb to send the VIEW intent to the app I just get the error
Error: Activity not started, unable to resolve Intent { act=android.intent.actio
n.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp.DeepLinkActivity }
DeepLinkActivity.java
public class DeepLinkActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getAction() == Intent.ACTION_VIEW) {
Uri uri = getIntent().getData();
}
}
}
Android Manifest declaring deeplink activity
<activity android:name="com.myapp.DeepLinkActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="gizmos"
android:scheme="example" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data
android:host="www.example.com"
android:pathPrefix="gizmos"
android:scheme="http" />
</intent-filter>
</activity>
ADB command to send the view intent
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp.DeepLinkActivity
But I don't think I even need the full path to the activity
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp
Try skipping package param entirely. I had exactly same problem and it works.
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos"
Comment out the second data part from your Android Manifest. As per google documentation of deep link :
"Intent filters may only contain a single data element for a URI pattern. Create separate intent filters to capture additional URI patterns."
In your manifest you defined your scheme as "http" but in your intent constructor you are using "example."
The problem is you have one intent filter for 2 types of deep links:
<activity
android:name="app.myActivity"
android:label="#string/app_name"
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" />
<!-- Accepts URIs that begin with "example://gizmos”-->
<data
android:host="gizmos"
android:scheme="example" />
</intent-filter>
<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="/gizmos"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
</activity>
And you will be able to use both on the ADB shell. Please see my full answer here
Simply try as follows
Command:
adb shell am start -d your-deep-link
Example:
adb shell am start -d rmagazine://opensetting/v1
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).