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

时间:2016-03-25 22:30:20

标签: android intentfilter

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

<?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>

我在应用链接上阅读了这个extensive guide,解释了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 =&#34; false&#34;对于tertiary.com上的意图过滤器!

这是一个Android错误吗?我如何确保IntentFilterIntentService仅验证我已设置android的intent过滤器:autoVerify =&#34; true&#34;并留下另一个?

2 个答案:

答案 0 :(得分:7)

  

这是Android的错误吗?

由于行为似乎有记录,我将其描述为限制。引用the documentation

  

当存在android:autoVerify属性时,安装您的应用会导致系统尝试验证与您所有应用的意图过滤器中的网址相关联的所有主机。

(强调补充)

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

  

如何确保IntentFilterIntentService仅验证我已设置android的intent过滤器:autoVerify =&#34; true&#34;并留下另一个?

我想将它们放在不同的应用程序中。

答案 1 :(得分:1)

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

阅读文档,仅当它存在属性时才说明。它不会检查值。

<块引用>

当 android:autoVerify 属性存在时,安装您的应用 导致系统尝试验证与该关联的所有主机 您应用的所有意图过滤器中的网络 URI。