androidtrusted-web-activitytwa

How to implement Play Store Purchases from a Trusted Web Activity?


I'm considering developing an Android App with the bulk of the application being written as a PWA and made available inside the Android app as a Trusted Web Activity (TWA).

What I'm not able to find on the Internet (and perhaps I don't know the right wording) is how to make the TWA kick off a Purchase event in the Android wrapper.

Perhaps this is not the right way to solve it? It would also be acceptable to make the TWA switch to another Activity (is that a thing?) and have that activity kick off the Play Store purchase.


Solution

  • The current way to do it would be indeed making the TWA start another Activity, implemented as native, that would handle the payment flow. This Activity can be started by using an intent-filter with a custom schema.

    By the end of the payment flow, you'd need to relaunch the TWA, passing any details as parameters (query strings, custom headers or by modifying the referrer)

    Having said that, work to implement this is a bit involved and the results are still not seamless. We're looking into ways of enabling this flow better.

    Update: There's ongoing work on an extension billing library for Trusted Web Activity that will simplify this flow, and will also be integrated into the CLI tool, Bubblewrap.