zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

Duplicate call method 'barcodeResult'

Open alexei-28 opened this issue 5 years ago • 1 comments

Android Studio 3.6

in app/build.gradle:

implementation 'com.journeyapps:zxing-android-embedded:3.5.0'

in fragment


 @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ScanCodeBinding binding = DataBindingUtil.inflate(inflater, R.layout.scan_code, container, false);
        binding.setHandler(this);
        View rootView = binding.getRoot();
     `decoratedBarcodeView.decodeContinuous(bacCodeCallback);`
        return rootView;
    }


 private BarcodeCallback bacCodeCallback= new BarcodeCallback() {
        @Override
        public void barcodeResult(BarcodeResult result) {

        }

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

  @Override
    public void onResume() {
        super.onResume();
       decoratedBarcodeView.resume();
}
@Override
    public void onPause() {
        super.onPause();
        decoratedBarcodeView.pause();
    }

but method barcodeResult call TWICE after scan.

alexei-28 avatar Dec 30 '19 08:12 alexei-28

This is expected - decodeContinuous will call the method every time it detects a barcode. You need to implement your own filtering of the results. For example, you can add a check to ignore barcodes if another one has been scanned less than a second ago, or if the data is the same as the previous scan.

rkistner avatar Jan 07 '20 12:01 rkistner