【问题标题】:Deeplink intent filter to a particular pathPrefix?将意图过滤器深层链接到特定的 pathPrefix?
【发布时间】:2015-10-23 15:45:07
【问题描述】:

我已经在我的 Android 应用上启用了深度链接,它运行良好。

但是,我希望意图过滤器仅侦听特定的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> 

【问题讨论】:

    标签: android deep-linking


    【解决方案1】:

    通过该清单,您告诉您的设备启动包含该意图过滤器的 Activity,该过滤器的所有 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 - MATCH
    • http(s)://(www.)mydomain.com/e?a=b - 匹配
    • http(s)://(www.)mydomain.com/Xe - 不匹配
    • http(s)://(www.)mydomain.com/X/e?a=b - 不匹配

    【讨论】:

    • 我也会建议这个解决方案,这是我的第一个意图。
    • 是否需要指定 2 个主机(一个带 www,另一个不带)?仅仅 www.mydoman.com 还不够吗?
    【解决方案2】:

    由于您粘贴的代码适用于 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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多