How to implement Android applications with wildcard domains?

Android has guidelines for implementing app links. That is, if my application claims that it processes certain web links, and I try to open this link to any other application, the system intercepts this and displays the user directly to my application, and not to the browser, so that I can display relevant content directly in your application. Very comfortably.

What I am missing in the manual are two things:

  • How to implement links to wildcard applications. I would like my application to process links to * .example.com, that is, all links to subdomains example.com (test.example.com, something.example.com, etc.);

  • How to implement application links only for certain paths on my site. For example, I want to intercept test.example.com/something, but not test.example.com/other. The first one should come to my application, the other - to my browser;

The corresponding iOS manual shows that iOS handles both of these scenarios (although part of the template is not clear from the documents, and I needed to clarify with Apple Support what you needed to place the association file in the root domain, not the subdomain).

Can Android App process wildcard domains and only a subset of paths?

+8
android ios applinks
source share
2 answers
  • Unfortunately, it seems that Android cannot handle wildcard domains .

If you look at the API manual for the data tag ( https://developer.android.com/guide/topics/manifest/data-element.html ), you may notice that they refer to the fact that the wildcard is available for pathPattern and mimeType, but not for the host.

The point is that, as CommonsWare explained in another post on this subject ( https://stackoverflow.com/a/165189/ )

domains are checked during installation, and there is no way to add new domains, except by sending a new version of the application with a new manifest.

Thus, you will have to manually list all available subdomains and update the application when starting a new subdomain.

Here you declare several subdomains:

  <activity android:name="MainActivity"> <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="http" /> <data android:host="subdomain1.example.com" /> <data android:host="subdomain2.example.com" /> <data android:host="subdomain3.example.com" /> </intent-filter> </activity> 
  1. Yes, you can only handle a subset of paths

This is the same idea, just list the paths you want using the path attribute (again, see the data tag API manual above).

If you use query strings or path parameters, prefer to use pathPrefix.

If necessary, you can use wildcards here, choosing pathPattern instead.

The part of the URI path that should begin with /. The path attribute indicates the full path that maps to the full path in the Intent. The pathPrefix attribute specifies a partial path that maps only to the initial part of the path in the Intent. The pathPattern attribute specifies the full path that maps to the full path in the Intent, but may contain the following wildcards: An asterisk ('') matches a sequence from 0 to many occurrences of the immediately preceding character. The period followed by an asterisk (".") Matches any sequence from 0 to many characters.

Here are some examples:

  <activity android:name="MainActivity"> <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="http" /> <data android:host="subdomain1.example.com" /> <data android:host="subdomain2.example.com" /> <data android:host="subdomain3.example.com" /> <data android:path="/path1" /> <!-- matches /path1 only --> <data android:pathPrefix="/path2" /> <!-- matches /path2, /path2/something or also /path2?key=value etc... --> <data android:pathPattern="/wild.*" /> <!-- matches /wild, /wild3, /wilderness etc... --> </intent-filter> </activity> 
+9
source share

Android cannot handle the substitution domain as such (according to their documentation today), but this will answer your request to include and exclude specific / paths.

To implement deep binding for a URL, for example -

 http://example.com/gizmos?1234, http://example.com/gizmos/1234, http://example.com/gizmos/toys/1234, etc. 

Your XML should look something like this:

 <activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" > <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "example://gizmos" --> <data android:scheme="example" android:host="gizmos" /> </intent-filter> <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "http://example.com/gizmos" --> <data android:scheme="http" android:host="example.com" android:pathPrefix="/gizmos" /> </intent-filter> </activity> 

Now, given that you were able to achieve this, here's how you restrict access to parts of the content of your application -

 <?xml version="1.0" encoding="utf-8"?> <search-engine xmlns:android="http://schemas.android.com/apk/res/android"> <noindex uri="http://example.com/gizmos/hidden_uri"/> <noindex uriPrefix="http://example.com/gizmos/hidden_prefix"/> <noindex uri="gizmos://hidden_path"/> <noindex uriPrefix="gizmos://hidden_prefix"/> </search-engine> 

And part of the manifest -

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.Gizmos"> <application> <activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" > <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW"/> ... </activity> <meta-data android:name="search-engine" android:resource="@xml/noindex"/> </application> <uses-permission android:name="android.permission.INTERNET"/> </manifest> 

For more information and an explanation of this example, you can take a look at -

Android Deep Linking

Hope this helps, Happy Coding

+3
source share

All Articles