Android深层链接忽略了某些网址 [英] Android Deep linking omit certain url

查看:168
本文介绍了Android深层链接忽略了某些网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功实现了到我的应用程序的深层链接,但是我遇到了问题.

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

此意图过滤器可处理所有链接,但我不想捕获某个网址,即

https://www.example.com/hello/redirect/

到目前为止我尝试过的事情:

我尝试输入要手动捕获的所有URL

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

但是我的主页URL https://www.example.com不起作用.

如果我使用

android:pathPrefix="/"

然后,它将开始再次捕获所有URL,包括我要忽略的URL.

我也尝试过使用android:pathPattern,但是它无法理解像^((?!redirect).)*$这样的复杂正则表达式,当我在字符串和所有形式中尝试时,都可以正常工作.

任何人都知道我该如何省略某些URL?

更新:

如@PLNech所建议,此处,我添加了所有需要使用android:pathPrefix捕获的URL,并使用android:path: "/"捕获我主页的URL,即 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/">

解决方案

Android深度链接机制没有提供显式排除某些URL的方法:您可以 要么显式地包含android:path的路径,要么包含与android:pathPrefix的前缀匹配的路径,或者与android:pathPattern的通配符匹配的路径,您可以在其中使用*.*./p>

对于您而言,您将必须使用"/"并具有每个指向随应用程序打开的网站(包括您的首页)的链接,或者使每个深层链接共享一个公共前缀.

您还可以查看airbnb的 DeepLinkDispatch 库,该库似乎

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

解决方案

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.

这篇关于Android深层链接忽略了某些网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆