Android Deep linking omit certain url

廉价感情. 提交于 2019-11-30 03:48:50

问题


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/">

回答1:


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.




回答2:


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/.



来源:https://stackoverflow.com/questions/41422305/android-deep-linking-omit-certain-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!