androidapplinkstrusted-web-activityandroid-app-links

App links are working only when opened from outside of Android TWA application


TLDR: app links trigger correctly from chrome, but not from inside my TWA app.

I have an Android App that opens Trusted Webview Activity launching my website.

What I want to achieve: When I navigate through my website inside TWA app and click a button with URL https://example.com/app/feature I want HelloActivity to launch.

Setup: I have set up app link in app manifest file:

<activity android:name=".HelloActivity" android:exported="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" />
                <data android:host="example.com" />
                <data android:path="/app/feature" />
            </intent-filter>
</activity>

Problem: When I click the button with url https://example.com/app/feature while in chrome browser, app link intent is triggered correctly and my app opens with HelloActivity inflated. However when I click the button with url https://example.com/app/feature while inside my TWA app it does not trigger the intent.

I have set up app links correctly but they trigger only in chrome browser not from inside the app. I expected app links also to trigger when scrolling through the TWA application.


Solution

  • Solution: this helped me solve it. To open native activity from the inside of TWA I have used custom schema URL on my website: app://feature And then in activity's intent filter:

    <data android:scheme="app" /> 
    <data android:host="feature" />