Exclude few Urls from deeplinking

Seshu Vinay picture Seshu Vinay · Nov 28, 2014 · Viewed 8.9k times · Source

I could successfully implement deeplinking of app using following filter in the intent-filter in my Manifest:

   <data  android:host="myhost.com"
    android:pathPrefix="/v"
    android:scheme="http" />

Eg. My Urls are:

 http://myhost.com/v/login1.php?id=123&name=abc&type=a
 http://myhost.com/v/login1.php?id=123&name=abc&type=b

I want to exclude

http://myhost.com/v/login1.php?id=123&name=abc&type=c

Now I want to exclude a few Urls which have same prefix. Is it possible or Do I need to explicitly specify all urls with android:path ? If so, how to deal with values of query parameters?

Answer

Jing Li picture Jing Li · Jul 1, 2015

Unfortunately we can't exclude any certain url, since Android doesn't provide that option.

The best practice is to give as precise pathPrefix as possible.

Specify only host without any pathPrefix is OK, as long as all actions carried out by the application makes sense. But if there is any link which should do something specific while the application could not handle, then it should let the web service handle it properly. In this case, whitelisting everything is not a good idea, if your web service can do more than your application.

Some people like matching only host in manifest, then handle different cases in code. You never know what unexpected url could be captured, if it really make senses to handle it by "else" condition. Better, do it carefully, only list the pathPrefix that we are sure about.

Back to your case, most of the time, I believe that application is able to handle the url if it's only different in query parameter. Because it belongs to the same action (by API's route handler), just different results. Only when the whole routing is different, you should treat it differently by giving the right pathPrefix.

So the valid example could be:

// To handle:
http://myhost.com/v/login1?id=123&name=abc&type=a
// To exclude:
http://myhost.com/v/login2?id=123&name=abc&type=a

Then in AndroidManifest.xml:

<data android:scheme="http"
      android:host="myhost.com"
      android:pathPrefix="/v/login1" />

Note: In case you stumble upon noindex.xml, that is for App Indexing, not for deep linking exclusion.