1

I am trying to add subdomain for a single TWA App. I have done the asset linking done from website to app. I can see the URL bar every time even if the linking is done.

strings.xml

<resources>
<string name="app_name">XXXX </string>
    <string name="asset_statements" translatable="false">
    [{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.xxxx.com\"}
    },{
        \"relation\": [\"delegate_permission/common.handle_all_urls\"],
        \"target\": {
            \"namespace\": \"web\",
            \"site\": \"https://www.abcd.xxxx.com\"}
    }]

</string>
</resources>

AndroidManifest

 <activity
        android:name="android.support.customtabs.trusted.LauncherActivity">

        <!-- Edit android:value to change the url opened by the TWA -->
        <meta-data
            android:name="android.support.customtabs.trusted.DEFAULT_URL"
            android:value="https://www.xxxx.com" />
        <meta-data
            android:name="android.support.customtabs.trusted"
            android:value="https://www.abcd.xxxx.com" />

//added intent filter in android manifest

 <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>

            <!-- Edit android:host to handle links to the target URL-->
            <data
                android:scheme="https"
                android:host="www.xxxx.com"/>
            <data
                android:scheme="https"
                android:host="www.abcd.xxxx.com"/>

i can see the www.xxxx.com without a url bar but for www.abcd.xxxx.com i can see the URL bar.

https://developers.google.com/digital-asset-links/tools/generator

i checked the linking using the below link and it returns that host has granted app deep linking

Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48

3 Answers3

0

I've been digging around to try and solve this myself, and while I don't have an answer just yet, I've made enough progress where I am able to change the subdomain from within my TWA and not have the url bar showing.

My first step was to set my asset statements to have a wildcard:

    <string name="asset_statements">
        [{
            \"relation\": [\"delegate_permission/common.handle_all_urls\"],
            \"target\": {
                \"namespace\": \"android_app\",
                \"site\": \"https://*.newvote.org\"}
        }]
    </string>

I was then able to set my android.support.customtabs.trusted.DEFAULT_URL meta-data to any URL on my subdomain and it worked happily with my current assetlinks.json file located on my web-server. However I could not change my subdomain/url from within the app, as this would open the URL bar.

As I was testing I started trying out different URL's (our web-app has many sub-domains) and I noticed that previously tested domains started to work. It seems that by setting URL's as DEFAULT_URL the app is somehow caching these as trusted. I have tried uninstalling the app and clearing my Chrome cache and this persists, so I'm not sure how this is working.

Something I can definitely confirm for you is that setting:

<meta-data android:name="android.support.customtabs.trusted" android:value="@string/app_url" />

Will not work, you are trying to set metadata on a class name, and when I explore the android.support.customtabs.trusted class I can see that DEFAULT_URL is the only property that is used for URL definition.

My conclusions so far: I dont believe you need multiple asset_statements. I don't believe you need multiple meta-data fields and I don't believe setting multiple data:host fields in the intent-filter is having the desired effect. The bottom line I think is currently there's no supported way to handle subdomains in a TWA.

EDIT:

Just confirmed that this magical caching of trusted URL's is happening as I test and install different versions of the app. Installing the latest version on another device reverts back to a single trusted URL and the sub-domain navigation is failing.

Community
  • 1
  • 1
Rohan
  • 456
  • 3
  • 16
0

you should add the assetlinks.json file to every subdomain your app might visit to

so all these links should return the asset file

  https://www.xxxx.com/.well-known/assetlinks.json
  https://www.abcd.xxxx.com/.well-known/assetlinks.json

also make sure it follows these guidelines.

200 response and content-type application/json redirects will not work

aalluri7
  • 11
  • 2
0

For each domain and subdomain add intent with "android:autoVerify="true":

        <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="sub.domain.com" />
        </intent-filter>

OR

res/values/strings.xml:

...
<string-array name="additional_trusted_origins">
    <item>https://sub1.google.com</item>
    <item>https://sub2.google.com</item>
    <item>https://sub3.google.com</item>
</string-array>
...

and AndroidManifest.xml:

...
<activity android:name="com.google.androidbrowserhelper.trusted.LauncherActivity"
    android:label="@string/app_name">
    ...
    <meta-data
       android:name="android.support.customtabs.trusted.DEFAULT_URL"
        android:value="https://google.com" />
    <meta-data
        android:name="android.support.customtabs.trusted.ADDITIONAL_TRUSTED_ORIGINS"
        android:resource="@array/additional_trusted_origins" />
    ...
    <intent-filter android:autoVerify="false">
            <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="*.google.com" />
    </intent-filter>
    ...
</activity>
...
gesin
  • 1
  • 1