Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Deep linking omit certain url

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/">
like image 448
Aayush Thakur Avatar asked Jan 02 '17 06:01

Aayush Thakur


1 Answers

The Android deep linking mechanism does not provide a way to explicitly exclude some URLs: you can either include explicitly paths with android:path, include paths matching a prefix with android:pathPrefix or matching a wildcard with android: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.

like image 79
PLNech Avatar answered Sep 22 '22 14:09

PLNech