Multiple subdomain support with App Links
Asked Answered
H

5

14

I've been reading the docs for supporting app links for android and the website my app supports works with subdomains but there's too many subdomains and they are built dynamically. I was wondering if there is a way to support many subdomains without having to specifiy them all in the intent-filter tag.

Here is the link to the example from google: http://developer.android.com/training/app-links/index.html#request-verify The example is in the Supporting app linking for multiple subdomains location.

I thought a regex would work but apparently that's not supported when defining the host. I don't want to list all of them since that would mean having to push a new release with every new subdomain created

<activity ...>
    <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:scheme="https" />
        <data android:host=".*.example.org" />
        <data android:pathPattern="/.*" />
    </intent-filter>
</activity>

I would prefer not to use a third party lib or service.. But any suggestions that work for you would be appreciated to understand how to make this work.

Hammurabi answered 3/12, 2015 at 14:23 Comment(0)
M
13

Quoting from: Verify Android App Links

Alternatively, if you declare your hostname with a wildcard (such as *.example.com), you must publish your assetlinks.json file at the root hostname (example.com). For example, an app with the following intent filter will pass verification for any sub-name of example.com (such as foo.example.com) as long as the assetlinks.json file is published at https:/ /example.com/.well- known/assetlinks.json:

<application>
  <activity android:name=”MainActivity”>
    <intent-filter android:autoVerify="true">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" android:host="*.example.com" />
    </intent-filter>
  </activity>
</application>

It seems the previous answers are outdated and Android now does has a support for wildcard in host name. As per the documentation it is now supported.

Merrile answered 12/2, 2018 at 14:6 Comment(0)
U
13

the website my app supports works with subdomains but there's too many subdomains and they are built dynamically

You are welcome to implement app links for some subset of those (e.g., the ones that are known at the time you build the app). You might even consider cooking up a Gradle plugin that can generate the appropriate manifest elements from a list of domains somewhere.

However, the domains are checked at install time, and there is no means to add new domains except by shipping a new edition of the app with a new manifest.

I was wondering if there is a way to support many subdomains without having to specifiy them all in the intent-filter tag.

No, sorry. Android checks the domains and retrieves the JSON file at install time.

I thought a regex would work but apparently that's not supported when defining the host

You cannot download JSON from a regex.

I don't want to list all of them since that would mean having to push a new release with every new subdomain created

Then either support some common subset, or do not support app links for now. It is conceivable, if somewhat unlikely IMHO, that Google will offer more flexible options for this in the future.

UPDATE: 2019-11-08: It appears that wildcards are supported as of Android 7.1.

Unformed answered 3/12, 2015 at 14:29 Comment(3)
Just as I expected. thanks for answering, I might end up buiding a gradle script that can generate an appropriate manifest. Since that is the only way I can truly support all of them. Makes sense to have that data ready on install time.Hammurabi
I have the same issue right now. @Miguel, any solutions at the time?Vilhelmina
This answer is no longer valid, Vaibhav Raj has example from official documentation that this scenario is supported now. I'm not sure what is the best way to handle that, maybe changing accepted answer by @Miguel or just adding some kind of errata.Halmahera
M
13

Quoting from: Verify Android App Links

Alternatively, if you declare your hostname with a wildcard (such as *.example.com), you must publish your assetlinks.json file at the root hostname (example.com). For example, an app with the following intent filter will pass verification for any sub-name of example.com (such as foo.example.com) as long as the assetlinks.json file is published at https:/ /example.com/.well- known/assetlinks.json:

<application>
  <activity android:name=”MainActivity”>
    <intent-filter android:autoVerify="true">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" android:host="*.example.com" />
    </intent-filter>
  </activity>
</application>

It seems the previous answers are outdated and Android now does has a support for wildcard in host name. As per the documentation it is now supported.

Merrile answered 12/2, 2018 at 14:6 Comment(0)
O
4

You can add your domain as *.example.com. At the docs it's said that the wildcard can be used as the first character of the host. So you could change the manifest to something like this:

<intent-filter . . . >
    <data android:scheme="https" />
    <data android:host="*.example.org" />
    . . .
</intent-filter>

And this should work with the subdomains:

  • example.org
  • www.example.org
  • anyOtherSubDomain.example.org
Otterburn answered 15/2, 2017 at 9:3 Comment(1)
Your example supported by deep linking but not by app linking (android:autoVerify="true"). In your case we have this error : E/HostsVerifier: Invalid host to verify (*.example.org):Input host is not valid.Elis
E
3

After multiple test, multiple subdomains supported since android 7.1 (api level 25). On previous version during app installation we got this error : E/HostsVerifier: Invalid host to verify (*.example.org):Input host is not valid.

Elis answered 17/8, 2017 at 11:55 Comment(1)
is this causing a crash in the app?Gannie
A
0

Speaking of verifying links in Android 12 and above for subdomains, you can utilize wildcards (*) in the manifest:

<application>
  <activity android:name="MainActivity">
    <intent-filter android:autoVerify="true">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" android:host="*.example.com" />
    </intent-filter>
  </activity>
</application>

However, if you are using a navigation graph and have already defined your deep links within it, please note the following adjustment: Instead of using a single star, you should use ".*" in the URI pattern:

<deepLink
    android:autoVerify="true"
    app:uri=".*.example.com/p/{id}" />

Please note that link verification in Android can involve additional considerations, such as associating the verified links with digital asset links or using the App Links Assistant in Android Studio. please check the document.

Alyssa answered 1/7, 2023 at 9:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.