【问题标题】:How to use ZXing to pull only certain data in an app?如何使用 ZXing 仅拉取应用程序中的某些数据?
【发布时间】:2017-11-03 12:07:53
【问题描述】:

我正在创建一个 Android 应用程序,它可以让您扫描食物并查看名称、保质期、卡路里和营养信息。

我已经使用这个 youtube 教程实现了 ZXing 条码扫描器:https://www.youtube.com/watch?v=otkz5Cwdw38

但我不知道如何指定扫描条形码时要提取的数据。我有两张表食物和营养信息,当用户在扫描条形码后单击确定时,我希望能够添加到这些表中。

我对此很陌生,因此我们将不胜感激。

【问题讨论】:

  • 你也想只扫描条形码或二维码????

标签: java android barcode zxing


【解决方案1】:

将以下依赖项添加到您的 build.gradle 文件中。

compile 'me.dm7.barcodescanner:zxing:1.9.8'

简单用法

1.) 为您的 AndroidManifest.xml 文件添加摄像头权限:

<uses-permission android:name="android.permission.CAMERA" />

2.) 一个非常基本的活动如下所示:

public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
        setContentView(mScannerView);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        Log.v(TAG, rawResult.getText()); // Prints scan results
        Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}

【讨论】:

  • 谢谢!我不明白它是如何知道获取我想要的数据是否有意义?
  • 在 handleResult 方法中,您将获得解析它所需的数据并按照您的逻辑显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 1970-01-01
  • 1970-01-01
  • 2014-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多