【发布时间】:2020-05-28 16:05:08
【问题描述】:
遇到有关通过意图过滤器解决传入意图的问题,并想知道这种行为的确切原因。
我有一个具有如下意图过滤器的活动
<activity android:name=".deeplink.DeeplinkActivity">
<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:host="*"
android:scheme="dltest" />
</intent-filter>
</activity>
一切都按预期工作,即它确实解析了 dltest://test1
格式的 URI然后我必须支持 https://www.mine.com/ 格式的 URL 为此,我向相同的意图过滤器添加了一个新的数据标签,导致
<activity android:name=".deeplink.DeeplinkActivity">
<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:host="www.mine.com"
android:scheme="https" />
<data
android:host="*"
android:scheme="dltest" />
</intent-filter>
</activity>
现在它确实处理这两种类型的 URI,但它也处理所有意图,方案为 https,主机为未指定格式的任何内容(通配符),例如:https://developer.android.com
<data
android:host="*"
android:scheme="https" />
我知道可以通过在同一个活动中将两个数据标签分成两个不同的意图过滤器来解决这个问题,但我无法弄清楚上述解析策略是如何在任何地方工作的。谁能帮我解释一下原因
【问题讨论】:
-
相同类型的多个元素导致条件的逻辑或。因此,您的两个
<category>元素意味着带有DEFAULT或BROWSABLE的Intent将匹配Intent。您的实验表明,<data>的逻辑 OR 是由单个属性决定的。因此,具有https或dltest和www.mine.com或*的主机的Intent将匹配。这只是一个猜测——我已经很长时间没有尝试过这种多个<data>元素的样式了。
标签: android android-intent intentfilter