获得扫描结果使用zxing什么时候?什么时候、结果、zxing

2023-09-05 00:11:31 作者:稳掌三界权

我目前使用的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:

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.