Launching another activity from a Trusted Web Activity (TWA)

1k views Asked by At

I have problems trying to launch another activity from the TWA via the intent URI. "intent://#Intent;scheme=subscriptionschemetwa;package=com.package.www.twa;end" The package name is unique in reality, of course.

I've played around with them, added host, action, extras etc. to URI, but nothing had an effect.

As I'm new to native development, I'd appreciate some help. The app itself is not publicly available on Google Play yet (only internally), it's signed and packaged with Bubblewrap, and installed via adb. The intent URI's fallback does work in the sense it takes me to the Store's internal listing, but I have no idea why the activity is not started.

The XML chunk:

        <activity android:name="SubscriptionActivity">
            <intent-filter>
                <data
                    android:host="com.package.www.twa"
                    android:scheme="subscriptionschemetwa" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>

The Activity is the same from bulk create, with an added log just to check if it ever enters the method. It does not.

class SubscriptionActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        println("------test------")
        setContentView(R.layout.activity_subscription)
    }
}

The logcat logs after clicking on the link pointing to the intent URI seem to show there is no attempt to start the activity at all, rather it goes directly to the store. I can run the activity directly through the adb shell just fine.

09-11 20:57:30.419  1595 25814 I CLP     : startActivity sender check.  com.android.chrome to Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=market://details?id=com.package.www.twa&referrer=com.android.chrome flg=0x10000000 pkg=com.android.vending cmp=com.android.vending/com.google.android.finsky.activities.MarketDeepLinkHandlerActivity (has extras) }
09-11 20:57:30.607  9562  9804 I AppIconSolution: load=com.package.www.twa, bg=96-96, dr=132-132, forDefault=false, density=0
09-11 20:57:30.611  9562  9804 I AppIconSolution: load=com.package.www.twa-theme2, bg=96-96, dr=132-132, tarScale=0.65, relScale=0.48, mask=false
09-11 20:57:30.786 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.794 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.917 22165 22200 I Finsky  : [842] lge.run(418): Dropped referrer for com.package.www.twa because dropped_already_installed
09-11 20:57:30.934 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]
09-11 20:57:30.940 22165 22165 I Finsky  : [2] hze.a(11): Selecting account [xxxxxxxxxxxxxxxxxxxxxxxxxx] for package com.package.www.twa. overriding=[true]

Any input is appreciated, I've been on this for days now and I just can't wrap my head around it.

1

There are 1 answers

0
Blackness On BEST ANSWER

So it seems that the intent URI was wrong. I actually managed to start the activity without issues using what I thought was a deprecated way to invoke activities via intent URIs. But hey, it works. The URI I ended up using was:

subscriptionschemetwa://www.package.com

or in more general terms

scheme://host

Hope it helps someone avoid wasting time like I did :D