Deep-linking intent does not work
Solution 1
EDIT:
Ok first make sure that your package is reachable by adb:
adb shell am start -n com.example.simon.test/.activities.MainActivity
Then to accept multiple data tags you need different intent filters (that's the way it worked for me unlike all the other examples I've seen on the net). E.g.:
<intent-filter>
...
<data android:scheme="http"
android:host="example.com"/>
</intent-filter>
<intent-filter>
...
<data android:scheme="http"
android:host="example.com"
android:pathPrefix="/gizmos"/>
</intent-filter>
NOTE that in the above example the pathPrefix starts with a forward slash !
I am not sure why Google's Docs are so misleading or maybe that was for some different version of adb, but the above changes worked perfectly for me. This helped: Source
This is how I made the Chrome browser route specific links to my app:
<activity
android:name=".activities.DeepLinkActivity"
android:label="@string/app_name">
<!-- Accept chrome links -->
<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="example.com"
android:pathPrefix="/"/>
</intent-filter>
<!-- Accept adb data flag -->
<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="example.com"/>
</intent-filter>
</activity>
NOTE The 1st filter works on Google Chrome while the 2nd one works on the ADB.
NOTE2 The app choice menu won't be shown if the link is entered into the browser's address bar. It has to be a <a href="http://example.com"></a>
link in side some page.
In my opinion everything here is rather blurry and really not how I expected it all to work. But that's how it works on my device. Hope this helps (and works) for you too.
Solution 2
After some tests this is what worked for me:
<activity android:name=".activities.MainActivity">
<intent-filter android:label="@string/app_name">
<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.example.com"
android:pathPrefix=""
/>
<data android:scheme="myschema"
android:host="example"
android:pathPrefix=""
/>
</intent-filter>
</activity>
This works when clicking any link in the browser such as "http://www.example.com", "http://www.example.com/" or "http://www.example.com/whatever". The same with "myschema://example/whatever".
Also works with adb
using this command (with any of those URLs):
adb shell am start -W -a android.intent.action.VIEW -d "http://www.example.com" com.example
Hope it helps to get you started.
When everything is working you will probably want to configure a different pathPrefix
for different activities.
Solution 3
In my case, I am using an emulator and not an actual usb connected device, and hence I had to change -d to -e, like so :
adb shell am start -W -a android.intent.action.VIEW -e "http://www.example.com" com.example
Note the -e before the deep link.
Solution 4
In my case, I was putting deep linking intent filter in MainActivity which is also main launcher. That caused the problem.
After I created another separate activity and put intent filter there, it solved the problem. Hope this can help others who are facing the same issue.
Solution 5
First, read @user3249477's answer on this page.
I just wanted to add that instead of what he wrote, you can condense it by using pathPattern:
<activity
android:name=".activities.DeepLinkActivity"
android:label="@string/app_name">
<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="example.com"
android:pathPattern=".*"/>
</intent-filter>
</activity>
The ".*" matches both the empty string and "/", so both cases are covered. If you end up trying to handle multiple scheme's and host's this becomes especially important, so you don't have to spam a powerset of {http, https} X {"", "/"} X {"foo", "bar", etc.}
Mahoni
Updated on July 05, 2022Comments
-
Mahoni about 2 years
I followed the insttructions on https://developer.android.com/training/app-indexing/deep-linking.html, but when I want to trigger the intent through
adb
with:adb shell am start -W -a android.intent.action.BROWSEABLE -d "http://example.com/gizmos" com.myapp.android
I just get
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp.android }
<activity android:name=".activities.DeepLinkActivity" android:label="@string/title_activity_deep_link"> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> <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="example.com" android:pathPrefix="/gizmos" /> </intent-filter> </activity>
Have I made any obvious mistakes?
-
Mahoni almost 10 yearsPerfect, it's still missing the fact that you need to set
android:export="true"
(probably for non-launch activities?) and that for instance if your activity is not living in the root directory then the test command would beadb shell am start -n com.example.simon/.test.MainActivity
-
Mahoni almost 10 yearsAnyway, I am not sure if this is a conceptional problem, but why doesn't the MainActivity get now started when I enter this HTTP address into the Browser App?
-
Simas almost 10 years@Mahoni Nice catch. Exported tag allows components of other apps to be able to call it. Can you update your question with your current command and manifest please?
-
Mahoni almost 10 yearsYes, so basically I have only the
http
scheme as data for the intent filter left and when I enterhttp://example.com/gizmos
into the Browser App or click on a link that directs there that I would be asked whether I want to open this site in my app, but maybe I am misunderstanding the deep-linking concept here. -
Simas almost 10 years@Mahoni first of all your action is a category. Use
-a android.intent.action.VIEW
. For me calling activities in separate folders worked too. I'm looking into the browser's now. Afaik different browsers have different schemes set so that might be in the way. -
Mahoni almost 10 yearsOh okay, I was thinking that
BROWSABLE
was for intent action start from the Browser or otherwise links that would start the browser, but okay. I would expect now that when I want to open a link in a mail program which points tohttp://example.com/gizmos
would ask me, should it be started with Browser or my app. -
Mahoni almost 10 yearsWell, I'd like to say it works now, but it does not. I have not installed Chrome yet. I am mainly testing from within a mail with links inside Gmail. It just does not react to it and jumps to the Browser (Internet app) immediately. When I hold on the link it asks me what to do with the link (copy url, open in browser, share link).. so still no clue what is stopping this :-/
-
Simas almost 10 yearsMahoni, it works fine for me but requires DEFAULT category to be set on the filter. If the links are set to be always started with your browser it won't show you the app choice menu. Try going to settings->apps->all->browser(or what ever) and Clear defaults.
-
Mahoni almost 10 yearsPerfect, at least I get the dialog now. Still not showing up the app, also working with multiple intent-filter and data to try to catch at least one case. Not sure what else might block it.
-
Simas almost 10 years@Mahoni I believe both DEFAULT and BROWSING categories are required, make sure you use them. Also please tell me your API and browser versions. Also are you using gmail app or just the browser?
-
Mahoni almost 10 yearsYes, so I am using three categories with
VIEW
,BROWSABLE
andDEFAULT
. API wise I am working with Android 4.2 and Android 4.4 (Browser version is 4.1.2). I am using Gmail for testing the opening links currently. -
Mahoni almost 10 yearsWaaaah, got it! Due to copy pasting I changed the tag element for
VIEW
from<action>
to<category>
got it now! Of course an intent-filter does not work without defining an<action>
tag. -
Simas almost 10 years@Mahoni just wanted to ask if you didn't set view to be a category :P
-
Mahoni almost 10 yearsGreat. Thanks for your perseverance.
-
cwhsu over 9 yearsGreat example for showing that we need different intent filters! Also, the slash in the pathPrefix is important. Well done!
-
Yash Sampat almost 9 yearsThis was useful. Thanks ... :)
-
Angel Koh over 8 yearsyou need to separate myschema://example to another intent filter. according to developer.android.com/training/app-indexing/deep-linking.html - "Note: Intent filters may only contain a single data element for a URI pattern. Create separate intent filters to capture additional URI patterns."
-
peresisUser over 7 years+1 for "/" between package name and path to activity. The docs can be really misleading and non-complete.
-
Punit Vajpeyi over 6 yearsThanks, It saved my day.
-
avisper over 6 yearsPerfect solution for the Manifest. but for the adb, this command works for me: adb shell am start -a android.intent.action.VIEW -d "example.com" com.exampleapp
-
Iam ByeBlogs over 6 yearsthis is worked for me, thanks mate.. you saved my day ;)
-
Iam ByeBlogs over 6 yearsby the way, its only on android.. how about ios..?
-
gonzobrains almost 6 yearsCan you use ".*" data for host as well?
-
EDISON J over 5 yearsHow run this in chrome browser ?
-
Mouaad Abdelghafour AITALI about 5 years@Ferran Maylinch , thank you for your answer ,can we use any site in android:host="www.example.com" ?
-
Ferran Maylinch about 5 years@pic Sure, that URL was just an example
-
Saman Sattari almost 5 yearsNote2 saved my day
-
AskQ over 4 yearsandroid:pathPrefix="" pathprefix cannot be empty
-
CoolMind over 4 yearsYes, this is a good approach, and I keep searching for a solution.
-
Chaki_Black over 4 yearsTesting with
adb
doesn't give the real production picture. E.g. I wanted to usemyschema://example/whatever
for opening an application from email, but GMAIL application doesn't recognize it as a link. Tried to send it as link (wrapped as link's href, using html for email), but Google transforms it as ordinary text. So, the only way I could launch an application and make it see as a link - using onlyandroid:scheme="https"
. -
Samet Sığırcı over 3 years@Chaki_Black I've got the same issue, did you solve that?
-
user3825344 over 2 yearsI also have the same problem when attempting to use a custom scheme. Was there a solution?
-
arun-r about 2 years@IamByeBlogs iOS you got anything similar to this?