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

3

12

In my app I have 3 activities, MainActivity, SecondaryActivity and TertiaryActivity. I want SecondaryActivity to be a default app link handler for a particular domain on Android 6, as described in this guide. At the same time, I want another activity, TertiaryActivity, to be able to handle links from another domain, but not be a default handler, as I don't own the domain. Here's my AndroidManifest to illustrate:

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

I read through this extensive guide on app links that explains the mechanics of app link handling and app verification on Android, and here's the messages I see in logcat related to app verification:

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.

As you can see it attempts to verify both secondary.com and tertiary.com, even though I explicitly set android:autoVerify="false" for the intent filter on tertiary.com!

Is this an Android bug? 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?

Hidie answered 25/3, 2016 at 22:30 Comment(1)
I also found a weird issue with setting autoVerify="false" on one of the intent-filters to activity with another one having it true like in your case. This created weird behaviour where the link from messages app just opened the app instead of going through the filter but only if the app wasn't killed. I've decided to avoid setting it to "false" as it becomes unpredictable.Burn
S
18

Is this an Android bug?

Since the behavior appears to be documented, I would describe it as a limitation. Quoting 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.

(emphasis added)

My interpretation of that is that if auto-verify behavior is all-or-nothing at the app level. It is unclear to me why they wrote it that way. If that is the long-term plan, I would have expected the autoVerify attribute to be on <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?

Put them in separate apps, I guess.

Steck answered 25/3, 2016 at 22:36 Comment(1)
This is such an unintuitive behavior that exists. I would be very interested if someone finds a workaround for this behavior.Fechner
N
1

I think you should leave out that android:autoVerify="false" instead of setting it.

Reading the documentation it says only if the attribute it present. It wont check the value.

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.

Narvik answered 24/2, 2021 at 13:49 Comment(1)
It doesn't work either way. As @Steck noted, it's all-or-nothing.Eldoraeldorado
V
0

If you do not add

android.intent.category.BROWSABLE 

This will prevent Android from auto verifying that particular intent-filter.

Vietnamese answered 31/10, 2022 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.