2

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?

shyam
  • 9,134
  • 4
  • 29
  • 44
krisdr
  • 23
  • 3

1 Answers1

0

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>
        ...
andreban
  • 4,621
  • 1
  • 20
  • 49
  • It works like a charm, thank you very much @andreban! I have an additional question: is it possible to remember the last domain that was opened, with a parameter in the AndroidManifest.xml? Using your example : I'm opening the app for the first time (so it will open www.google.com) I go to another authorized domain (github.com) Now, if I close the TWA, I would like it to open now on github.com – krisdr Jan 25 '21 at 09:22
  • Remembering the last domain used to open the TWA is possible - you'll need to implement your own LauncherActivity, extending the original LauncherActivity and add your own getLaunchingUrl() implementation. However, if the TWA starts domain A and the user navigates to domain B inside the TWA, it won't be able to remember the last domain. – andreban Jan 25 '21 at 10:00