question

Danielle Cox avatar image
Danielle Cox asked Danielle Cox answered

Barcode Scanner

I am using the built in barcode scanner and following the example over all. What I am seeing is that on a mini it works as expected, however, on a station, the very first barcode (QR if that matters) that is scanned is not sending me a broadcast. Any thoughts? I would be interested to see if this is a known problem and/or if there is any sort of workaround or testing that I can try?

Upon further testing I see that if I use the built in scanner for some other purpose, the first time back also fails.

My code consists of:

protected void startBarcode()  {
    mBarcodeScanner = new BarcodeScanner(this);

    registerReceiver(barcodeReceiver, new IntentFilter(BarcodeResult.INTENT_ACTION));
    Bundle extras = new Bundle();
    extras.putBoolean(Intents.EXTRA_LED_ON, false);
    extras.putBoolean(Intents.EXTRA_SCAN_QR_CODE, true);
    extras.putBoolean(Intents.EXTRA_SCAN_1D_CODE, true);
    mBarcodeScanner.executeStartScan(extras);
}

and

@Override
protected void onPause() {
    super.onPause();

    if (mBarcodeScanner != null) {
        unregisterReceiver(barcodeReceiver);
        mBarcodeScanner = null;
    }
}

and

private BroadcastReceiver barcodeReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        BarcodeResult barcodeResult = new BarcodeResult(intent);

        if (barcodeResult.isBarcodeAction()) {
            String barcode = barcodeResult.getBarcode();
            unregisterReceiver(barcodeReceiver);
            mBarcodeScanner = null;
            if (barcode != null) {
                gotBarcode(barcode);
            }
        }
    }
};

Thanks!

Danielle

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Danielle Cox avatar image
Danielle Cox answered

I moved the registerreciever further up in the code and it works.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community