yuriy-budiyev / code-scanner

Code scanner library for Android, based on ZXing
MIT License
1.1k stars 267 forks source link

scan Continuously more than one time #86

Open tahlilgar opened 4 years ago

tahlilgar commented 4 years ago

I want to scan the barcode more than one time but this code just worked for the first scan. then I should close and open again scan activity to scan the second barcode and more...

my code in on create activity: mCodeScanner.setDecodeCallback(new DecodeCallback() { @Override public void onDecoded(@NonNull final Result result) {

                new Thread() {
                    public void run() {
                        while (i++ < 2) {
                            try {
                                runOnUiThread(new Runnable() {

                                    @SuppressLint("SetTextI18n")
                                    @Override
                                    public void run() {

                                        List<String> s= Arrays.asList(txtKalaCodeList.getText().toString().split("-"));
                                        if(s.size()!=0)
                                        {
                                            if(!s.contains(result.getText()))
                                                txtKalaCodeList.setText(result.getText()+(txtKalaCodeList.getText().toString().equals("")?"": "-"+txtKalaCodeList.getText().toString()));

                                        }else {

                                            txtKalaCodeList.setText(result.getText()+(txtKalaCodeList.getText().toString().equals("")?"": "-"+txtKalaCodeList.getText().toString()));
                                        }
                                    }
                                });
                                Thread.sleep(300);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }.start();
            }
        });
mohammadnr2817 commented 4 years ago

Based on Library document <_code in kotlin_> : mCodeScanner!!.scanMode = ScanMode.CONTINUOUS mCodeScanner!!.decodeCallback = DecodeCallback { result: Result -> val res = result.text.toLowerCase() if (res.startsWith("example")) { toastThis(res) } }