Android Deeplink pathPrefix属性被忽略

Max*_*lis 7 android uri deep-linking intentfilter android-manifest

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

  <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:pathPrefix=""
                android:scheme="example" />

            <!-- Accepts URIs that begin with "example://com” -->
            <data
                android:host="com"
                android:pathPrefix=""
                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>
Run Code Online (Sandbox Code Playgroud)

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

出于某种原因,即使使用前缀"/some/sample/page.htm"定义了为DeeplinkActivity定义的intent过滤器也是如此.

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

JSt*_*hen 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>
Run Code Online (Sandbox Code Playgroud)

这将只接受开头为HTTP的URI http://www.example.com/some/sample/page.htm或URI的与begining example://comexample://shelf

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