获得扫描结果使用zxing什么时候? [英] getting scan result when using zxing?

查看:266
本文介绍了获得扫描结果使用zxing什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的Zxing库在我的应用程序。扫描一本书吧code例如后,我怎么像的形象,描述等,从扫描结果。

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

推荐答案

Zxing扫描各种条码codeS / QR codeS,所以你需要做的第一件事是,如果其产品UPC弄清楚或QR code:

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:

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            String response = data.getAction();

            if(Pattern.matches("[0-9]{1,13}", response)) {
                // response is a UPC code, fetch product meta data
                // using Google Products API, Best Buy Remix, etc.          
            } else {
                // QR code - phone #, url, location, email, etc. 
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(response));
                startActivity(intent);
            }
        }
    }   

有若干将返回给一个UPC code产品的元数据可用的web服务。一个相当COM prehensive人会成为谷歌的搜索API购物。例如,你可以用UPC = 037988482481产品的JSON重新presentations有看起来像这样的网址:

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:

<一个href="https://www.googleapis.com/shopping/search/v1/public/products?country=US&key=your_key_here&restrictBy=gtin:037988482481" rel="nofollow">https://www.googleapis.com/shopping/search/v1/public/products?country=US&key=your_key_here&restrictBy=gtin:037988482481

您将需要替换your_key_here与您的谷歌API密钥。

You'll need to replace "your_key_here" with your Google API key.

百思买还提供了一个RESTful 产品API 了解他们所携带的产品,是可搜索的通过UPC code。

Best Buy also offers a RESTful products API for all of the products they carry which is searchable by UPC code.

您将要使用的AsyncTask来获取产品元数据,一旦你有UPC。

You'll want to use an AsyncTask to fetch the product metadata once you have the UPC.

这篇关于获得扫描结果使用zxing什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆