Android 尽管 android:autoVerify="false" 仍尝试验证主机

Android tries to verify host despite android:autoVerify="false"

在我的应用程序中,我有 3 个活动,MainActivity、SecondaryActivity 和 TertiaryActivity。我希望 SecondaryActivity 成为 Android 6 上特定域的默认应用程序 link 处理程序,如 this guide 中所述。同时,我希望另一个 activity、TertiaryActivity 能够处理来自另一个域的 link,但不是默认处理程序,因为我不拥有该域。这是我的Android清单来说明:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.antonc.applinktest"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity android:name=".SecondaryActivity"
                  android:label="@string/app_name"
                  android:theme="@style/AppTheme.NoActionBar">
            <intent-filter android:autoVerify="true"> <!-- TRUE -->
                <data android:scheme="https"
                      android:host="secondary.com"/>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>

        <activity android:name=".TertiaryActivity"
                  android:label="@string/app_name"
                  android:theme="@style/AppTheme.NoActionBar">
            <intent-filter android:autoVerify="false"> <!-- FALSE -->
                <data android:scheme="https"
                      android:host="tertiary.com"/>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

我在应用程序 link 上通读了这个 extensive guide,它解释了应用程序 link 在 Android 上处理和应用程序验证的机制,这是我看到的消息在 logcat 中与应用程序验证相关:

03-25 17:54:45.640 1481-1481/com.google.android.gms D/IntentFilterVerificationReceiver: Received ACTION_INTENT_FILTER_NEEDS_VERIFICATION.

03-25 17:54:45.644 1481-30947/com.google.android.gms I/IntentFilterIntentService: Verifying IntentFilter. verificationId:12 scheme:"https" hosts:"tertiary.com secondary.com" package:"com.antonc.applinktest".

03-25 17:54:46.762 1481-30947/com.google.android.gms I/IntentFilterIntentService: Verification 12 complete. Success:false. Failed hosts:tertiary.com,secondary.com.

如您所见,它会尝试验证 secondary.com 和 tertiary.com,即使我明确设置了 android:autoVerify="false" 用于 tertiary.com!

上的意图过滤器

这是 Android 错误吗?我如何确保 IntentFilterIntentService 仅验证我为其设置的意图过滤器 android:autoVerify="true" 而将另一个过滤器排除在外?

Is this an Android bug?

由于该行为似乎已记录在案,因此我将其描述为一种限制。引用 the documentation:

When the android:autoVerify attribute is present, installing your app causes the system to attempt to verify all hosts associated with the web URIs in all of your app's intent filters.

(强调)

我对此的解释是,如果自动验证行为在应用程序级别是全有或全无。我不清楚 他们为什么 那样写。如果这是长期计划,我希望 autoVerify 属性位于 <application>.

How do I make sure that IntentFilterIntentService only verifies the intent filter for which I have set android:autoVerify="true" and leaves the other one out?

我想将它们放在单独的应用程序中。

我认为你应该省略 android:autoVerify="false" 而不是设置它。

阅读文档它只说它存在的属性。它不会检查值。

When the android:autoVerify attribute is present, installing your app causes the system to attempt to verify all hosts associated with the web URIs in all of your app's intent filters.