android - 您如何调用 Android 应用程序并从 Chrome 中的网页返回结果?

标签 android google-chrome android-intent progressive-web-apps

查看https://developer.chrome.com/multidevice/android/intents那么从应用程序将结果返回到 Chrome 浏览器的最佳方法是什么?有 browser_fallback_url 但有任何类型的 result_callback 处理程序吗?问题类似于 How to get a result back to your web page from an Intent triggered from inside Chrome?

编辑:为此 https://code.google.com/p/chromium/issues/detail?id=572067 开始发布

最佳答案

Chrome 不会以 startActivityForResult 启动 Activity 因此没有简单的方法可以让接收应用程序直接回调到网站或 Web 应用程序,并像您期望的那样在本地进行响应。

虽然有一个解决方案,但它需要 native 应用程序同意该协议(protocol)。

ZXing QR Code Scanner支持使用名为 ret 的简单查询字符串参数将 QR 码扫描结果回调到站点

On Android, you can invoke Barcode Scanner from a web page and have the result returned to your site via a callback URL. For example, when 01234 is scanned, to have the user return to http://foo.com/products/01234/description, simply link to a URL like this, where {CODE} is a placeholder for the value of the returned code:

http://zxing.appspot.com/scan?ret=http%3A%2F%2Ffoo.com%2Fproducts%2F%7BCODE%7D%2Fdescription&SCAN_FORMATS=UPC_A,EAN_13

Note that the URL in the ret= parameter is URL-escaped, and that {CODE} is used as a placeholder for the scanned value (above, it appears as %7BCODE%7D). SCAN_FORMATS, and other parameters, can be set here as well to control the scan behavior. For example is can be used to supply a comma-separated list of format names.

您可以在 native 应用程序和 Web 应用程序中设置类似的方案,以便在 native 应用程序中完成操作并使用名为 ret 的查询字符串参数启动时(或任何你想要的)然后它知道它需要启动一个新的 Activity 并在 Intent 中设置回调 URL 并在查询字符串中添加额外的数据,这样你的浏览器将打开它需要的所有数据。

它确实有一些问题:

  • 您不能定位一个窗口,因此可能会打开一个新窗口,然后您将打开您的网络应用程序两次
  • 您需要网络应用和 native 应用来支持如何返回数据的约定。

关于android - 您如何调用 Android 应用程序并从 Chrome 中的网页返回结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197933/

相关文章:

Android Studio espresso 测试记录器 - 滑动事件

android - 在 Trusted Web Activity 中地址栏不隐藏

android - 如何实现对可运行线程的简单 RxJava 调用?

java - 在两个 Android 应用程序之间共享凭据

android - 标准 Intent URI 损坏?

android - 谷歌.android.gms :play-services-oss-licenses not working after obfuscation

javascript - 通过 Mobirise 制作的 chrome 动画出现故障

ajax - 按后退按钮时 Chrome 显示 ajax 响应

html - svg 动画无法在 Chrome 中正确显示

Android 类扩展 MainActivity 上的 View 和位置