I've put together a PWA and wanted to convert it into an Android App. I've done so and my Android app consists of Main Activity and TWA that I start from the Main Activity.
Is there a way to switch from inside the TWA to some other activity on some event in the PWA running in this TWA? Like button click. Preferably from the HTML/Javascript of the PWA itself.
The end goal is to ad ads to the app (I'm using some paid APIs in the PWA so I need to at least break even and cannot monetize it on the web development side since Google AdSense and likes need context rich web-apps like blogs) and I've figured out that Google AdMob don't show up in TWA, they require a native Android Activity.
This question is closely related but I don't know where to put this URI: Launching another activity from a Trusted Web Activity (TWA)
Thank you!
Yes, it is possible to start a different Activity. You will need to define a custom schema and link to that schema from the PWA:
This is defined inside AndroidManifest.xml
, where the Activity you want to open from the PWA is specified. In the example below, we want to open ReviewActivity
from the PWA, so we define:
<activity android:name=".ReviewActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="doom-fire" android:host="review" />
</intent-filter>
</activity>
Then, in the web application, whenever you link to doom-fire://review
, ReviewActivity
will be opened:
<a href="doom-fire://review">Rate app now!</a>
I wrote a complete blogpost for the in-app review use-case that you may want to check out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.