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

标签 android intentfilter android-app-links

在我的应用程序中,我有 3 个 Activity ,MainActivity、SecondaryActivity 和 TertiaryActivity。我希望 SecondaryActivity 成为 Android 6 上特定域的默认应用程序链接处理程序,如 this guide 中所述.同时,我希望另一个 Activity 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,即使我为 tertiary.com 上的 intent 过滤器明确设置了 android:autoVerify="false"!

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

最佳答案

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 尝试验证主机,尽管 android :autoVerify ="false",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36229090/

相关文章:

android - 在 Android 中下载文件

android - "android.intent.category.DEFAULT"的目的是什么?

android - 无法从 ResolveInfo 实例获取 Intent 过滤器

android - 从 Google Play 安装应用程序时,Android 中的 AppLinks(已验证的 Deeplinks)不起作用

android - 具有多个 TextView 和焦点的选框

android - 如何访问 list 中声明的​​广播接收器并更改某些属性

java - CameraBridgeViewBase 类的 setMaxFrameSize 方法在 OpenCV Java 中到底做了什么?

android - 仅适用于特定 NFC 标签的应用程序

android - 应用程序链接在 Android 中无法正常工作

android - App Linking 不适用于测试环境