gpt4 book ai didi

android - 更精确的 URI 方案

转载 作者:行者123 更新时间:2023-11-30 00:51:42 24 4
gpt4 key购买 nike

问题

我有多种方案可以将用户引导至应用程序的不同部分。问题是,由于所有这些方案都以相同的方式开始,因此用户必须从 Android 应用程序选择器中选择他想去的地方(或者调用带有应用程序的底部框)。我希望我的方案更“精确”,以避免强制用户做出此决定。

代码

Activity1 方案触发器

 <intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="foobar.com" android:pathPrefix="/path/category"/>
<data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path/category"/>
</intent-filter>

Activity2 方案触发器

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="foobar.com" android:pathPrefix="/path"/>
<data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path"/>
</intent-filter>

我的 UriSchemes

foobar://foobar.com/path

http://foobar.com/path

foobar://foobar.com/path/category

http://foobar.com/path/category

最佳答案

由于 activity1 的 pathPrefix 是 Activity1 中相同的前缀,因此那里存在歧义 - 因此 android 将无法明确地解析对 activty1 的请求。

有几个选项:-

  1. 制作一个带有 Intent 过滤器的中间 DeepLinkActivity 以捕获基本方案/主机/路径前缀,并使用它手动处理 url 并转发到相关 Activity 。如果您将来有复杂的 url 结构,这会提供更大的灵 active 。

  2. 将 activity2 的 url 更改为唯一的(如果可能的话)

我会推荐选项 1

关于android - 更精确的 URI 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40929586/

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