trusted-web-activitytwabubblewrap

Is it possible to have multiple main domains (hostName) in a TWA?


I have a website available in several languages, each linked to a domain (.com, .co.uk, .de etc), and I’m doing a TWA with Bubblewrap for it.

I have set the .com as the main hostname of the TWA, and I have authorized the other domains as indicated in the official documentation. (https://developers.google.com/web/android/trusted-web-activity/multi-origin).

It works well, I can switch domains in the TWA without any problem (with a language switcher), and if I click on a .com link in google search results for example, or in an email, then it opens well in the TWA.

However, if I click on a .co.uk link, then it opens in the web browser, whereas I would like it to open in the TWA as well.

Is it possible to allow more than one main "hostname", or to allow multiple domains to be recognized and opened automatically in the TWA?


Solution

  • Yes, you will need to add the extra domains to the intent-filter in AndroidManifest.xml.

    Using the twa-multi-domain sample, the main domain in the app is www.google.com and github.com and www.wikipedia.com are extra domains. After adding the 2 extra domains, this is how the section on AndroidManifest.xml should look like (lines 13 to 16 are new):

                ...
                <activity android:name="com.google.androidbrowserhelper.trusted.LauncherActivity"
                android:label="@string/app_name">
    
                ...
    
                <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="www.google.com"/>
                    <data android:scheme="https"
                        android:host="github.com"/>
                    <data android:scheme="https"
                        android:host="www.wikipedia.com"/>
                </intent-filter>
            </activity>
            ...