Credntia / MVBarcodeReader

A Barcode scanner library for Android. Uses the Google Play Services' mobile vision api for barcode detection.
Apache License 2.0
68 stars 22 forks source link

Is it possible to start another scan session after a barcode has been scaned? #14

Closed roostaamir closed 7 years ago

roostaamir commented 7 years ago

Hi and thank you for your great library I am using the BarcodeCaptureFragment to initiate a scan session. I want to initiate the scan session on activity create (therefore I am adding the fragment to the activity in the onCreate method), and then when a barcode has been scanned, show the user a dialog, and when the user clicks the button on the dialog (I set the setCancelable to false), the dialog should be dismissed and the barcode scanning process should begin again

What I have done so for is this:

barcodeCaptureFragment.setListener(new BarcodeCaptureFragment.BarcodeScanningListener() {
            @Override
            public void onBarcodeScanned(Barcode barcode) {
                new AlertDialog.Builder(MainActivity.this)
                    .setMessage(String.format("DisplayValue is : %s\nRaw value is : %s", barcode.displayValue, barcode.rawValue))
                    .setPositiveButton("close", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    })
                    .show();

            }

            @Override
            public void onBarcodesScanned(List<Barcode> barcodes) {

            }

            @Override
            public void onBarcodeScanningFailed(String reason) {

            }
        });

The problem is that when a barcode is scanned, the dialog will be shown, and the camera will freeze and will not scan anything else unless I close the activity and open it again I could remove the fragment and add it again, but this does not seem to be a good approach Any suggestions on how I can do this?

iamMehedi commented 7 years ago

This is not readily available. But should be possible. You can try overriding void onBarcodeDetected(final Barcode barcode) if you are using SINGLE_AUTO mode, and comment out the mCameraSource.stop() line. Or you can try calling void initiateCamera() after the dialog is closed.

roostaamir commented 7 years ago

instead of changing your code, I used reflection to call initiateCamera method and it worked for me. Thank you

yyavci commented 5 years ago

instead of changing your code, I used reflection to call initiateCamera method and it worked for me. Thank you

exactly.I did the same. Method initiateCam = BarcodeCaptureFragment.class.getDeclaredMethod("initiateCamera"); initiateCam.setAccessible(true); initiateCam.invoke(fragment);