使用zxing时获取扫描结果?
我目前在我的应用程序中使用 Zxing 库。例如,扫描一本书的条形码后,如何从扫描结果中获取图像、描述等信息。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch(requestCode) {
case IntentIntegrator.REQUEST_CODE:
if (resultCode == RESULT_OK) {
IntentResult scanResult =
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
} else if (resultCode == RESULT_CANCELED) {
showDialog("failed", "You messed up");
}
}
}
感谢您的帮助
I am currently using the Zxing library in my app. After scanning the bar code of a book for example, how do I get things like the image, description, etc. from the scan result.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch(requestCode) {
case IntentIntegrator.REQUEST_CODE:
if (resultCode == RESULT_OK) {
IntentResult scanResult =
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
} else if (resultCode == RESULT_CANCELED) {
showDialog("failed", "You messed up");
}
}
}
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Zxing 扫描各种条形码/QR 码,因此您需要做的第一件事是确定它是产品 UPC 还是 QR 码:
有许多可用的 Web 服务可以在给定 UPC 代码的情况下返回产品元数据。相当全面的一个是 Google 的 Search API for Shopping。例如,您可以获得 UPC = 037988482481 的产品的 json 表示形式,其 URL 如下所示:
您需要将“your_key_here”替换为您的 Google API 密钥。
Best Buy 还为其所有产品提供 RESTful 产品 API,可通过 UPC 代码进行搜索。
获得 UPC 后,您将需要使用 AsyncTask 来获取产品元数据。
Zxing scans a variety of barcodes/QR codes, so the first thing you need to do is figure out if its a product UPC or a QR code:
There are a number of web services available that will return product meta data given a UPC code. A fairly comprehensive one would be Google's Search API for Shopping. For example, you can get a json representations of the product with UPC = 037988482481 with an URL that looks like this:
You'll need to replace "your_key_here" with your Google API key.
Best Buy also offers a RESTful products API for all of the products they carry which is searchable by UPC code.
You'll want to use an AsyncTask to fetch the product metadata once you have the UPC.
您不需要“IntentResult”或“IntentIntegrator”。
您可以执行以下操作:
然后在
onActivityResult
中:通过此操作,您可以扫描条形码,现在 Zxing 代码中有另一个库,它使用 Google API 来查找 ISBN。
在
Intents.java
类中,您可以了解意图需要哪些额外内容,而ISBNResultHandler
类则显示结果。希望它对将来的人有所帮助。
You dont need the 'IntentResult' or 'IntentIntegrator' for that.
You can do this:
And then in
onActivityResult
:With this you scan the barcode, now there is in the Zxing code another library that uses Google API for looking up that ISBN.
In the class
Intents.java
you have the info of what extras the intent needs and the classISBNResultHandler
shows what is the result.Hope it helps someone in the future.
您可以检查 Android ZXing 应用程序的功能。 Android客户端源码位于:ZXing Android客户端源码。对于 ISBN 编号,处理的源代码为:Android ZXing 应用的 ISBN 结果处理程序代码
对于产品和图书搜索,Android 代码从 ResultHandler.java:
You can check what the Android ZXing app does. The source for the Android client is in: ZXing Android client source code. For ISBN numbers, the source code for handling that is: Android ZXing app's ISBN Result Handler code
For product and book search, the Android code invokes these two functions from ResultHandler.java:
在您的
onActivityResult
中执行以下代码,您尚未调用
result.getContents()
。In your
onActivityResult
do like following codeYou haven't called
result.getContents()
.我只是想补充一点,如果您希望能够在没有 RuntimeException 的情况下按回,请使用 try catch 块包围您的 if 语句。所以:
希望这对您在没有它的情况下将面临的不可避免的崩溃有所帮助。
I just want to add that if you want to be able to press back without a RuntimeException surround your if statement with a try catch block. so:
Hope that helped the inevitable crash you would face without it.