关于通过 Intent 过滤器解析传入 Intent 的问题

Issue regarding resolution of incoming intents by intent filter

运行 进入有关通过意图过滤器解决传入意图的问题,并想知道此行为的确切原因。

我有一个 activity 具有如下意图过滤器

 <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,但它也处理所有带有 scheme 作为 https 和 host 作为任何未指定格式(通配符)的意图,例如:https://developer.android.com

<data
     android:host="*"
     android:scheme="https" />

我知道可以通过将两个数据标记分离到同一个 activity 内的两个不同的意图过滤器来解决这个问题,但我无法弄清楚上述解决策略在任何地方都是如何工作的。谁能帮我看看原因

Google 在其官方 android 文档之一中说

Although it's possible to include multiple elements in the same filter, it's important that you create separate filters when your intention is to declare unique URLs (such as a specific combination of scheme and host), because multiple elements in the same intent filter are actually merged together to account for all variations of their combined attributes. For example, consider the following:

<intent-filter> 
  <data android:scheme="https" android:host="www.example.com" />
  <data android:scheme="app" android:host="open.my.app" />
</intent-filter>

这似乎只支持 https://www.example.com and app://open.my.app. However, it actually supports those two, plus these: app://www.example.com and https://open.my.app

所以基本上就像 @commonsware 所说的那样,它在幕后执行有点合乎逻辑的 OR ...从而确保满足所有组合

来源:Create Deep Links to App Content