如何修复Zxing扫描仪,扫描一次后不仅扫描条形码,

时间:2019-04-01 07:59:04

标签: android zxing

我要创建一个新的应用程序,有3种扫描模式,一种用于壁橱,一种用于储物柜,一种用于锁定!所有代码都在处理结果中,并且在每次扫描后我都使扫描仪恢复ScannerPreview,这是第一次扫描后,扫描仪不仅扫描条形码,而且还扫描文本的问题,如果我说一分钟或更短的时间,会扫描并显示奇怪的数字!该如何解决?

我试图看看是否只有一次扫描会发生这种情况,

这是处理结果中发生的代码

public void handleResult(Result result) {
  final String myResult = result.getText();
  final String check = myResult.trim();
    if (State == 0) {
       ClosetTextId=check;
       if (LockerAmbinDB.CheckCloset(Integer.parseInt(check)) == true) {
     try {

        ClosedId = Integer.parseInt(check);
                LockerByCloset = LockerAmbinDB.GetAllLockerByCloset(ClosedId);
                temp=String.valueOf( LockerByCloset.get(countScan).getId());


                sub_text=temp.substring(ClosetTextId.length());
                //Toast.makeText(getContext(),"" +LockerByCloset.size()+ "", Toast.LENGTH_LONG).show();
            } catch (NumberFormatException nfe) {
           {
            State++;
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {

                    ClosetText.setVisibility(ClosetText.GONE);
                    LockerText.setVisibility(LockerText.VISIBLE);
                    LockerNextText.setText("אנא סרוק את לוקר " + sub_text+ "");
                    LockerNextText.setVisibility(LockerNextText.VISIBLE);
                    scannerView.resumeCameraPreview(BarCodeScanner.this);

                }
            }, 1200);

        }
        else{
            functions.showAlertDialog(
                    getActivity(),
                    "ארון לא נמצא",
                    "הארון אינו קיים באתר, נא סרוק ברקוד שנית.",
                    false);

            scannerView.resumeCameraPreview(BarCodeScanner.this);

        }
    }else {

        if (countScan < LockerByCloset.size()) {
            if (State == 1) {
                String total=ClosetTextId+""+check;
                try {
                    LockerId = Integer.parseInt(total);
                } catch (NumberFormatException nfe) {
                    Toast.makeText(getContext(), "Could not parse" + nfe, Toast.LENGTH_LONG).show();
                    //System.out.println("Could not parse " + nfe);
                }
                if(LockerId==LockerByCloset.get(countScan).getId()) {
                    LockText.setVisibility(LockerText.GONE);
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            scannerView.resumeCameraPreview(BarCodeScanner.this);
                            LockerText.setVisibility(LockerText.GONE);
                            LockText.setVisibility(LockText.VISIBLE);

                            State++;
                        }

                    }, 1200);

                }
                else{
                    functions.showAlertDialog(
                            getActivity(),
                            "לוקר שגוי",
                            "מספר לוקר שגוי,אנא סרקו את הלוקר הנכון.",
                            false);
                    scannerView.resumeCameraPreview(BarCodeScanner.this);
                }
            } else if (State == 2) {

                Locker locker = new Locker();
                locker.setClosetId(ClosedId);
                locker.setId(LockerId);
                locker.setLockId(myResult);
                locker.setIsUpdate(1);
                LockerAmbinDB.addLockBundle(locker);
                countScan++;
                State--;
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if(countScan < LockerByCloset.size()) {
                            temp=String.valueOf( LockerByCloset.get(countScan).getId());
                            sub_text=temp.substring(ClosetTextId.length());
                            scannerView.resumeCameraPreview(BarCodeScanner.this);
                            LockText.setVisibility(LockText.GONE);
                            LockerText.setVisibility(LockerText.VISIBLE);
                            LockerNextText.setText("אנא סרוק את לוקר " + sub_text + "");
                            LockerNextText.setVisibility(LockerNextText.VISIBLE);
                            //LockText.setVisibility(LockText.VISIBLE);
                        }
                        else{
                            scannerView.stopCamera();
                            CheckResultAndSend();
                        }
                    }
                }, 1200);

            }
        }

    }

0 个答案:

没有答案