我在清单文件中为我的 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>
我的应用程序中还有一些看起来相似的链接,但不应被视为深层链接。他们确实开始于http://www.example.com但它们有一个完全不同的前缀。例如:http://www.example.com/other/not/deep/link.htm .
由于某种原因,为 DeeplinkActivity 定义的意图过滤器正在被触发,即使它是使用前缀“/some/sample/page.htm”定义的。
前缀是否被忽略?如果不是,为什么在定义深度链接意图过滤器时应该使用 pathPrefix 属性?
删除 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 URIhttp://www.example.com/some/sample/page.htm
或 URIsh 开头example://com
or example://shelf
所以在你原来的问题中,http://www.example.com/other/not/deep/link.htm
不会触发深层链接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)