如果包含特定路径,则丢弃深层链接

问题描述

我的清单中有一个深度链接的实现,它运行良好

    <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.broWSABLE" />
          <data
              android:host="blablabla.com"
              android:scheme="https" />
          <data
              android:host="${applicationId}"
              android:scheme="bla" />
</intent-filter>

我想知道有没有办法不接受包含特定路径的深层链接 URL?例如。如果 blablabla.com/specificPath 不接受(不打开应用),但接受具有相同主机名的任何其他路径。

解决方法

Android {{3}} 没有提供明确排除网址的方法,最佳做法是使用深层链接专门定义您要访问应用的网址。

在这种情况下,访问 URL 如下:

www.blablabla.com/specificPath
www.blablabla.com/specificPath/
www.blablabla.com/specificPath/default.aspx
www.blablabla.com/specificPath/other/

您将使用 android:pathPrefix 定义意图过滤器的配置:

 <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data
              android:host="blablabla.com"
              android:scheme="https" 
              android:pathPrefix="/specificPath" />
</intent-filter>