gpt4 book ai didi

Android Deeplink pathPrefix 属性被忽略

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:51:46 28 4
gpt4 key购买 nike

我在 list 文件中为我的 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 定义的 Intent 过滤器被触发,即使它是用前缀“/some/sample/page.htm”定义的。

前缀是否被忽略?如果不是,为什么在定义深层链接 Intent 过滤器时应该使用 pathPrefix 属性?

最佳答案

删除 pathPrefix 并没有解决我的问题,无论前缀如何,我最终要么所有 http 深层链接都有效,要么都不有效。似乎前缀、主机和方案都相互渗透,所以在你的例子中 example://www.example.com/即使没有单独的数据元素定义它,也可能会触发深层链接。我最终发现您可以将它们分成不同的 Intent 过滤器,它们不会混合。

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

    <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://com 开头的 URI或 example://shelf

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

关于Android Deeplink pathPrefix 属性被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002909/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com