问题
So I'm excited to find out chrome mobile can invoke intent
However, Can I get the result back?
I have an input for users to type in barcode for an item.
If they are using chrome mobile, I want to invoke a barcode scanner app, and receive the scanned barcode back to the input field.
Can't find any relevant information on google.
Even a simple link to a documentation or example would help a lot.
Thank you.
回答1:
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.
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
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.
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.
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
- You need both web app and native app to support the contract of how to return the data.
来源:https://stackoverflow.com/questions/33195514/how-to-get-a-result-back-to-your-web-page-from-an-intent-triggered-from-inside-c