Android的深层链接路径preFIX属性被忽略 [英] Android Deeplink pathPrefix Attribute Is Being Ignored

查看:148
本文介绍了Android的深层链接路径preFIX属性被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在manifest文件中为我的Andr​​oid应用程序定义的深层链接:

I have a deeplink defined for my Android app in the manifest file:

  <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>

我也有我的应用程序的一些链接,看起来相似,但不应该被视为深层链接。他们与 http://www.example.com 开始,但他们有一个完全地不同preFIX。例如: http://www.example.com/other/not/deep/ link.htm

I have also some links in my app that look similar but should NOT be treated as deeplinks. They do begin with http://www.example.com but they have a completly different prefix. For example: http://www.example.com/other/not/deep/link.htm .

有关某些原因DeeplinkActivity定义的意图过滤器被trigerred即使它与preFIX/some/sample/page.htm。

For some reason the intent filter defined for DeeplinkActivity is being trigerred even though it is defined with the prefix "/some/sample/page.htm".

请问preFIX被忽略?如果不是,为什么定义的深层链接意图过滤器时,应该使用路径preFIX属性?

Does the prefix being ignored? if not why one should use the the pathPrefix attribute when defining the deeplink intent filter?

推荐答案

删除路径preFIX没有解决这个问题对我来说,我要么结束了所有的HTTP深层链接工作还是没有人,无论preFIX。这似乎是prefixes,主机和方案都渗入海誓山盟,让您的例子例如://www.example.com/ 大概也引发了深刻的链接即使没有单独的数据元素定义它。我最终搞清楚,你只需将其分成不同的意图过滤器和他们不会混合。

Removing the pathPrefix didn't solve the problem for me, I either ended up with all http deep links working or none of them, regardless of prefix. It seems like the prefixes, hosts and schemes all bleed into eachother, so with your example example://www.example.com/ would probably also trigger a deep link even though none of the individual data elements define it. I ended up figuring out that you can just separate them into different intent-filters and they wont mix.

所以你的情况,你可以使用:

So in your case you could use:

    <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的URI与 http://www.example.com/some/sample/page.htm 开头或使用的URI <$ C $开始时C>例如:// COM 或例如://货架

this will only accept http URIs that begin with http://www.example.com/some/sample/page.htm OR URIs begining with example://com or example://shelf

所以在你的originial问题, http://www.example.com/other/not/deep/link.htm 不会引发深层链接。

so in your originial question, http://www.example.com/other/not/deep/link.htm will not trigger a deep link.

这篇关于Android的深层链接路径preFIX属性被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆