I have implemented deep linking to my app successfully but I am stuck with a problem.
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*.example.com"
android:scheme="https"/>
</intent-filter>
This intent filter handles all the links but I don't want to catch a certain url i.e.
https://www.example.com/hello/redirect/
What I tried so far:
I tried entering all the URLs that I want to catch manually
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/m/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/c/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/p/">
...
But then my home page URL https://www.example.com
doesn't work.
If i use
android:pathPrefix="/"
then this will start catching all the URLs again including the url i want to omit.
I also tried using android:pathPattern
, but it can't understand a complicated regex like this ^((?!redirect).)*$
which works fine when I try it in strings and all.
Anybody know how can I omit certain URLs?
UPDATE:
As suggested by @PLNech here, I added all the URLs that I need to catch using android:pathPrefix
and use android:path: "/"
to catch the URL of my home page i.e. https://www.example.com/
<data
android:host="*.example.com"
android:scheme="https"
android:path="/"/>
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/m/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/c/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/p/">
If I understand your problem correctly you want to exclude a particular URL from a certain list of URLs. What you tried was a good way to do that.
android:pathPattern
doesn't understand the complicated regex pattern as you said.I think the only way to solve your problem is to change the URL which you want to omit. Change the host or a part of that URL, or change the name
example.com
to, say,example2.com/hello/redirect/
.The Android deep linking mechanism does not provide a way to explicitly exclude some URLs from Android deep linking mechanism: you can either include explicitly paths with
android:path
, include paths matching a prefix withandroid:pathPrefix
or matching a wildcard withandroid:pathPattern
where you can use*
or.*
.In your case, you will have to either use
"/"
and have every link to your website opened with your app (including your homepage), or have every deep link share a common prefix.You can also have a look at airbnb's DeepLinkDispatch library, which seems to allow excluding specific URLs.