如何为特定的pathPrefix设置Deeplink意图过滤器?

7

我在我的安卓应用上启用了深度链接功能,目前运行良好。

但是,我希望意图过滤器只监听特定的pathPrefix,即http(s)://(www.)mydomain.com/e而不是其他任何pathPrefix

这可行吗? 我将我的意图过滤器代码附加在AndroidManifest.xml中。

<intent-filter android:label="My App Name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                android:host="www.domain.com"
                android:pathPrefix="/e" />
            <data android:scheme="http"
                android:host="mydomain.com"
                android:pathPrefix="/e" />
            <data android:scheme="https"
                android:host="www.mydomain.com"
                android:pathPrefix="/e" />
            <data android:scheme="https"
                android:host="mydomain.com"
                android:pathPrefix="/e" />
</intent-filter> 
2个回答

4
通过这段清单,您告诉设备启动包含该意图过滤器的活动,并处理所有具有以下内容的URL:
  1. 协议为http或https
  2. 主机为www.mydomain.com或mydomain.com
  3. 路径以/e为前缀
由于问题与pathPrefix相关,因此您的活动将处理所有路径以/e开头的URL。例如:
  • http(s)://(www.)mydomain.com/e - 匹配
  • http(s)://(www.)mydomain.com/eXXX - 匹配
  • http(s)://(www.)mydomain.com/e/a - 匹配
  • http(s)://(www.)mydomain.com/eXXX/a - 匹配
  • http(s)://(www.)mydomain.com/e?a=b - 匹配
  • http(s)://(www.)mydomain.com/Xe - 不匹配
  • http(s)://(www.)mydomain.com/X/e?a=b - 不匹配

我也建议使用这个解决方案,这是我的第一意图。 - Thomas R.
需要指定两个主机(一个带有www,另一个没有)吗?仅使用www.mydoman.com不就足够了吗? - Johnny Five

0

由于您粘贴的代码适用于该 pathPrefix,我猜想您只想捕获 http(s)://(www.)mydomain.com/e,而不是其他任何内容?
如果是这种情况,请使用 path 而不是 pathPrefix,如下所示。

<intent-filter android:label="My App Name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                android:host="www.domain.com"
                android:path="/e" />
            <data android:scheme="http"
                android:host="mydomain.com"
                android:path="/e" />
            <data android:scheme="https"
                android:host="www.mydomain.com"
                android:path="/e" />
            <data android:scheme="https"
                android:host="mydomain.com"
                android:path="/e" />
</intent-filter> 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接