Android Deeplink pathPrefix属性被忽略

时间:2015-06-23 12:31:47

标签: android uri android-manifest intentfilter deep-linking

我在清单文件中为我的Android应用程序定义了深层链接:

MyClass& operator= (const MyClass&);

我的应用程序中也有一些看起来相似但不应被视为深层链接的链接。它们以http://www.example.com开头,但它们具有完全不同的前缀。例如:http://www.example.com/other/not/deep/link.htm

出于某种原因,即使使用前缀“/some/sample/page.htm”定义了为DeeplinkActivity定义的intent过滤器,也会被触发。

前缀是否被忽略?如果不是为什么在定义deeplink intent过滤器时应该使用pathPrefix属性?

2 个答案:

答案 0 :(得分:5)

删除pathPrefix并没有为我解决问题,无论前缀如何,我或者最终都使用了所有http深层链接,或者都没有。似乎前缀,主机和方案都相互渗透,所以使用您的示例example://www.example.com/可能也会触发深层链接,即使没有单个数据元素定义它。我最终弄清楚你可以把它们分成不同的意图过滤器,它们不会混合。

所以在你的情况下你可以使用:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

                     <!-- Accepts URIs that begin with "example://shelf” -->
        <!-- Currently handles Ads deeplink structure (iPhone structure) -->
        <data
            android:host="shelf"
            android:pathPrefix=""
            android:scheme="example" />

        <!-- Accepts URIs that begin with "example://com” -->
        <data
            android:host="com"
            android:pathPrefix=""
            android:scheme="example" />

    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

        <!-- Accepts URIs that begin with http://www.example.com/some/sample/page.htm” -->
        <data
            android:host="www.example.com"
            android:pathPrefix="/some/sample/page.htm"
            android:scheme="http" />

    </intent-filter>

这只会接受以http://www.example.com/some/sample/page.htm开头的http URI以及以example://comexample://shelf

开头的URI

因此,在您的原始问题中,http://www.example.com/other/not/deep/link.htm不会触发深层链接。

答案 1 :(得分:3)

显然,某些其他数据标记中的空android:pathPrefix属性会导致特定数据标记(上述问题中的最后一个数据标记)忽略其自己的pathPrefix,即使它已被明确定义!

因此,此清单声明修复了最后一个数据标记的正常行为:

  <activity android:name="com.example.DeeplinkActivity"
    android:screenOrientation="portrait"
    android:theme="@style/MyBaseTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

                     <!-- Accepts URIs that begin with "example://shelf” -->
        <!-- Currently handles Ads deeplink structure (iPhone structure) -->
        <data
            android:host="shelf"
            android:scheme="example" />

        <!-- Accepts URIs that begin with "example://com” -->
        <data
            android:host="com"
            android:scheme="example" />

        <!-- Accepts URIs that begin with http://www.example.com/some/sample/page.htm” -->
        <data
            android:host="www.example.com"
            android:pathPrefix="/some/sample/page.htm"
            android:scheme="http" />
    </intent-filter>
</activity>