Android 深度链接省略某些 url

标签 android android-manifest deep-linking

我已成功实现到我的应用程序的深度链接,但我遇到了一个问题。

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

这个 intent 过滤器处理所有链接,但我不想捕获某个 url,即

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).)*$ 效果很好当我在字符串中尝试它时。

有人知道我怎样才能省略某些网址吗?

更新:

根据@PLNech 的建议here ,我添加了所有需要使用 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 deep linking mechanism不提供明确排除某些 URL 的方法:您可以 either使用 android:path 明确包含路径,包括使用 android:pathPrefix 匹配前缀的路径或使用 android:pathPattern 匹配通配符的路径,您可以在其中使用*.*.

在您的情况下,您将不得不使用 "/" 并使用您的应用打开指向您网站的每个链接(包括您的主页),或者让每个深层链接共享一个公共(public)前缀。

你也可以看看airbnb的DeepLinkDispatch图书馆,似乎allow excluding specific URLs .

关于Android 深度链接省略某些 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41422305/

相关文章:

android - 在后台任务中更新数据库 (Android)

java - 如何读取 3gp/AMR-NB 音频格式的原始值?

android - 如何在 android list 文件中声明两个包及其 Activity ?

java - 当 Angular 应用程序托管在子目录中时,如何在 Websphere 中进行 URL 重写

android - 使用包含路径和查询参数的(深度)链接打开应用程序

android - 如何从代码中以恒定速度连续滚动 ListView?

java - v4 androidmanifest.xml 文件未找到

android - 在同一台设备上安装同一应用程序的两个版本

android - Flutter 深层链接在浏览器中不起作用

android - 设备配置后无法安装 apk (Android 8.0)