【问题标题】:how to stop continuous scanning of QR code?如何停止连续扫描二维码?
【发布时间】:2018-11-12 11:01:24
【问题描述】:

**这是我的代码,我想要的是在第一次调用 callApi() 方法后扫描,但它会继续扫描**

  @Override
public void handleResult(Result result) {

    System.out.print("BAR_CODE  "+ result.getContents());
    System.out.print("BAR_CODEE  "+result.getBarcodeFormat().getName());
    barcode_number = result.getContents();
    productcode.setText(result.getContents());

    //resume Camera
    scanner_bar.resumeCameraPreview(this);

    dialog = new ProgressDialog(getActivity());
    dialog.setCancelable(true);
    dialog.setTitle("Loading");
    dialog.show();

    //callApi
    if(barcode_number != "") {

        callApi(barcode_number);
    }

};

【问题讨论】:

  • 您需要暂停或停止相机预览。
  • @Zaheer 可以加zbar Gradle或者github链接
  • @Zaheer 我在我的应用程序上使用 zxing 扫描仪,如果您需要,我可以帮助您实现。
  • 我以前用过zxing,但是扫描速度很慢,@Abhishekkumar
  • @SaurabhBhandari 谢谢你,先生,它对我有用。 scanner_bar.stopCamera()

标签: java android zxing zbar


【解决方案1】:

用这个替换你的代码

    @Override
public void handleResult(Result result) {

    System.out.print("BAR_CODE  "+ result.getContents());
    System.out.print("BAR_CODEE  "+result.getBarcodeFormat().getName());
    barcode_number = result.getContents();
    productcode.setText(result.getContents());

    //resume Camera
    scanner_bar.resumeCameraPreview(this);

    dialog = new ProgressDialog(getActivity());
    dialog.setCancelable(true);
    dialog.setTitle("Loading");
    dialog.show();

    //callApi
    if(barcode_number != "") {
        scanner_bar.stopCamera(); 
        callApi(barcode_number);
    }

};

【讨论】:

  • 谢谢先生,通过替换scanner_bar.resumeCameraPreview(this);使用scanner_bar.stopCamera();
  • @zaheer 欢迎您接受并支持我的回答。