简体   繁体   English

受信任 web 应用程序中本机 android 和渐进式 web 应用程序之间的双向桥接

[英]Two way bridge between native android and progressive web apps in trusted web application

As per current understanding from TWA documentation , we can pass message between native android and web using URL intents and query parameters/custom headers.根据 TWA 文档的当前理解,我们可以使用 URL 意图和查询参数/自定义标头在本机 android 和 web 之间传递消息。

I want to pass information from web to native and return response based on the action to that message in native to web on the same page.我想将信息从 web 传递到本机,并根据对同一页面上 web 的本机消息的操作返回响应。 I can do this by reopening another trusted web activity.我可以通过重新打开另一个受信任的 web 活动来做到这一点。 But this leads to page load and destroys the existing state of the page.但这会导致页面加载并破坏页面现有的 state。

In other words, I am trying to replicate a request-response type of behaviour in TWA without page transition on web.换句话说,我试图在 TWA 中复制请求-响应类型的行为,而无需在 web 上进行页面转换。

Sample use case: From PWA, I want to call android native code to print a string.示例用例:从 PWA 中,我想调用 android 本机代码来打印字符串。 In case of failure cases, I want to send back the error response to PWA.如果出现故障情况,我想将错误响应发送回 PWA。

Is there a way this can be done without reloading the page?有没有办法在不重新加载页面的情况下做到这一点?

Trusted Web Activities don't have a runtime communication bridge between Android and the web app, so the short answer to the question is that this cannot be done without reloading the page.受信任的 Web 活动在 Android 和 web 应用程序之间没有运行时通信桥,因此对该问题的简短回答是,如果不重新加载页面就无法完成。

There's a long discussion thread here: https://github.com/GoogleChrome/android-browser-helper/issues/55 .这里有一个很长的讨论线程: https://github.com/GoogleChrome/android-browser-helper/issues/55 Please, do chime in and describe your use case.请插话并描述您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM