Z型扫描仪,如何停止连续扫描?我希望扫描仪扫描一次后停止

时间:2018-11-12 11:01:24

标签: java android zxing zbar

**这是我的代码,我希望在扫描首次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);
    }

};

1 个答案:

答案 0 :(得分: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);
    }

};