简体   繁体   English

您如何调用Android应用并从Chrome的网页中获取结果?

[英]How do you call an Android app and get a result back from a web page in Chrome?

Looking at https://developer.chrome.com/multidevice/android/intents What is then the best way to get result back to Chrome browser from app? 查看https://developer.chrome.com/multidevice/android/intents那么从应用程序将结果返回到Chrome浏览器的最佳方法是什么? There is browser_fallback_url but is there any kind of result_callback handler? 有browser_fallback_url,但是有没有哪种result_callback处理程序? Question is similar to How to get a result back to your web page from an Intent triggered from inside Chrome? 问题类似于如何从Chrome内部触发的Intent将结果返回到网页?

Edit: Started issue for this https://code.google.com/p/chromium/issues/detail?id=572067 编辑:https://code.google.com/p/chromium/issues/detail?id=572067的开始发行

Chrome doesn't start the Activity with startActivityForResult so there is no simple method for the receiving App to callback directly into the web site or web app with a response as you would expect natively. Chrome不会使用startActivityForResult启动Activity,因此没有简单的方法可以让接收方的应用程序像您本来期望的那样直接回调到网站或具有响应的Web应用程序中。

There is a solution though but it requires the native app to agree to the protocol. 虽然有一个解决方案,但是它需要本机应用程序同意该协议。

The ZXing QR Code Scanner supports a callback into the site with result of the QR code scan using a simple Query String Parameter called ret ZXing QR Code扫描程序支持使用名为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. 在Android上,您可以从网页调用条形码扫描仪,然后将结果通过回调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: 例如,当扫描01234时,要让用户返回http://foo.com/products/01234/description ,只需链接到这样的URL,其中{CODE}是返回代码值的占位符:

http://zxing.appspot.com/scan?ret=http%3A%2F%2Ffoo.com%2Fproducts%2F%7BCODE%7D%2Fdescription&SCAN_FORMATS=UPC_A,EAN_13 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). 请注意,ret =参数中的URL是转义的URL,并且{CODE}用作扫描值的占位符(上面显示为%7BCODE%7D)。 SCAN_FORMATS, and other parameters, can be set here as well to control the scan behavior. 也可以在此处设置SCAN_FORMATS和其他参数以控制扫描行为。 For example is can be used to supply a comma-separated list of format names. 例如,可用于提供格式名称的逗号分隔列表。

You can set up a similar scheme inside your native app and web app so that when the action is completed in the native app and it was started with a query string parameter called ret (or whatever you want) then it knows it needs to start a new Activity with the callback URL set in the Intent and the extra data added in the query string, this way your browser will then open with all the data that it needs. 您可以在本机应用程序和Web应用程序中设置类似的方案,以便当该操作在本机应用程序中完成并且以名为ret (或任意所需)的查询字符串参数启动时,它就知道需要启动一个新的活动,并在Intent中设置了回调URL,并在查询字符串中添加了额外的数据,这样您的浏览器便会打开,并显示其所需的所有数据。

It does have a number of issues though: 但是确实存在许多问题:

  • You can't target a window so a new window might be opened up and you will then have your web app open twice 您无法定位窗口,因此可能会打开一个新窗口,然后将您的Web应用程序打开两次
  • You need both web app and native app to support the contract of how to return the data. 您需要Web应用程序和本机应用程序来支持如何返回数据的约定。

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

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