简体   繁体   English

条形码扫描在Android上暂停并恢复

[英]Barcode scanning pause and resume on android

I am starting to experience on java in android. 我开始在android中体验Java。 I have 3 EditText on the layout. 我在布局上有3个EditText。 I setup a barcode scanning window to scan the barcode. 我设置了条形码扫描窗口来扫描条形码。 After getting the first barcode, i pause the scanning and place it on the first EditText View. 获取第一个条形码后,我暂停扫描并将其放在第一个EditText视图上。 Then i resume. 然后我恢复。

The problem is that after the first scan, the camera does not scan again. 问题在于,第一次扫描后,相机不会再次扫描。 I tried many method, pause then resume and it still does not work. 我尝试了很多方法,暂停然后恢复它仍然无法正常工作。 Can someone help? 有人可以帮忙吗?

The code look like this. 代码看起来像这样。

private CompoundBarcodeView barcodeView;
private BarcodeCallback callback = new BarcodeCallback() {

    @Override
    public void barcodeResult(BarcodeResult result) {
        String code = null;
        if (result.getText() != null) {
            code = result.getText();

            if (code != null) {
                barcodeView.pause();
                job01 = (EditText) findViewById(R.id.jobTicket01);
                if (job01.getText().toString().trim().equals("")) {
                    job01.setText(code);
                    code = null;
                }else {
                    if (job02.getText().toString().trim().equals("")) {
                        job02.setText(code);
                        code = null;
                    } else{
                }
                }
            }
        }
        barcodeView.resume();

    }

    @Override
    public void possibleResultPoints(List<ResultPoint> resultPoints) {
    }
};

Thank in advance. 预先感谢。 Teddy 泰迪熊

I just avoid parsing data from the scan for a few seconds. 我只是避免从扫描中解析数据几秒钟。

I set up 2 values one for the data and another for the timestamp. 我为数据设置了一个值,为时间戳设置了另一个值。

String barcodeData = "";
Long scanTime = 0L;
        @Override
        public void receiveDetections(Detector.Detections<Barcode> detections) {
            final SparseArray<Barcode> barcodes = detections.getDetectedItems();
            if (barcodes.size() != 0) {
                txtBarcodeValue.post(new Runnable() {
                    @Override
                    public void run() {
                        if(barcodeData.equals("") && scanTime.equals(0L)){
                            barcodeData = barcodes.valueAt(0).displayValue;
                            scanTime = System.currentTimeMillis();
                            Log.d(TAG, "Barcode" + barcodeData);
                        }else if (!barcodeData.equals(barcodes.valueAt(0).displayValue)){
                            barcodeData = barcodes.valueAt(0).displayValue;
                            scanTime = System.currentTimeMillis();
                            Log.d(TAG, "New Barcode Scanned" + barcodeData);

                        }else if (barcodeData.equals(barcodes.valueAt(0).displayValue) && scanTime>(System.currentTimeMillis()-2500)) {
                            //Do Nothing
                            Log.d(TAG, "Barcode  Ignored ---------------" + barcodeData);
                        }else{
                            barcodeData ="";
                            scanTime = 0L;

                        }
                    }
                });
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM