Reputation: 599
I wrapped a Vue js web app using android to make it TWA(Trusted Web App).
Now I want to send firebase_token and other data from the Android part to the webapp in TWA. As all the Apis are on a web app and I don't want to call any API in Android.
In WebView we can send data from Android to the webapp using "WebViewController.evaluateJavascript()" but I don't know how can i send data from my Android(java) to web app.
Upvotes: 3
Views: 2300
Reputation: 49
As mentioned by @andreban, query-parameters may be used to pass info from native to the web-app.
Starting with Chrome 115, TWAs can also utilize postMessage
to communicate between the web and native app at runtime.
See the official docs here: https://developer.chrome.com/docs/android/post-message-twa
Upvotes: 0
Reputation: 4976
You can pass extra information to the Trusted Web Activity with query parameters.
If the parameter is the same across installs / launches, it can be added to the launchUrl itself.
If the parameter is more dynamic, you can implement your own LauncherActivity and override getLaunchingUrl()
to add extra parameters to the URL.
This article contains details on how to implement both solutions.
It is not possible to establish a communication bridge between the web app and the Android app at runtime (like a postMessage channel)
Upvotes: 1