Manoj Vayu
Manoj Vayu

Reputation: 99

How to prevent from scanning QR code when scanning barcode using zxing library?

I have come across this problem when scanning a barcode in my application, actually, the QR code is also present on some of the products beside barcode. so the zxing also scans QR code.

Upvotes: 1

Views: 2458

Answers (1)

PRATEEK BHARDWAJ
PRATEEK BHARDWAJ

Reputation: 2432

    public class QRScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
    // begin variable listing
    private ZXingScannerView mScannerView;



    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);
        setContentView(mScannerView);
        mScannerView.setFlash(true);
        List<BarcodeFormat> myformat = new ArrayList<>();
        myformat.add(BarcodeFormat.EAN_13);
        myformat.add(BarcodeFormat.EAN_8);
        myformat.add(BarcodeFormat.RSS_14);
        myformat.add(BarcodeFormat.CODE_39);
        myformat.add(BarcodeFormat.CODE_93);
        myformat.add(BarcodeFormat.CODE_128);
        myformat.add(BarcodeFormat.ITF);
        myformat.add(BarcodeFormat.CODABAR);
        myformat.add(BarcodeFormat.DATA_MATRIX);
        myformat.add(BarcodeFormat.PDF_417);

        mScannerView.setFormats(myformat);
        // Programmatically initialize the scanner view
                      // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        result=rawResult.getText();
        Log.e("qr_Text1",result);
        finish();
        // Prints the scan format (qrcode, pdf417 etc.)
        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }




}

compile 'me.dm7.barcodescanner:zxing:1.8.4'

Upvotes: 3

Related Questions