问题
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.
回答1:
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.
回答2:
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.
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/34068467/multiple-subdomain-support-with-app-links