Android本机和可信Web活动(TWA)之间的通信 [英] Communication between Android native and Trusted Web Activity(TWA)

查看:66
本文介绍了Android本机和可信Web活动(TWA)之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用android包装了一个Vue js Web应用程序,使其成为TWA(受信任的Web App).

I wrapped a Vue js web app using android to make it TWA(Trusted Web App).

现在,我想将firebase_token和其他数据从Android部件发送到TWA中的webapp.由于所有Apis都在网络应用程序上,因此我不想在Android中调用任何API.

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.

在WebView中,我们可以使用"WebViewController.evaluateJavascript()"将数据从Android发送到Webapp.但是我不知道如何将数据从Android(java)发送到Web应用.

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.

推荐答案

您可以使用查询参数将其他信息传递给受信任的Web活动".

You can pass extra information to the Trusted Web Activity with query parameters.

如果安装/启动过程中的参数相同,则可以将其添加到launchUrl本身.

If the parameter is the same across installs / launches, it can be added to the launchUrl itself.

如果参数更具动态性,则可以实现自己的LauncherActivity并覆盖 getLaunchingUrl()以向URL添加其他参数.

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.

在运行时无法在Web应用程序与Android应用程序之间建立通信桥(例如

It is not possible to establish a communication bridge between the web app and the Android app at runtime (like a postMessage channel)

这篇关于Android本机和可信Web活动(TWA)之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆