Phonegap-plugin-barcodescanner: Add continuous scanning support

Created on 7 Dec 2015  路  9Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

Please add support for continuous scanning, so that the barcode scanner does not close after a successful scan.

This could work like this:

var scans = 0,
    messageTimeout;
cordova.plugins.barcodeScanner.continuousScan(
    function(result) {
        // This method will get triggered for every barcode found (continuously)
        clearTimeout(messageTimeout);
        cordova.plugins.barcodeScanner.message('Product found');
        setTimeout(function() {
            messageTimeout = cordova.plugins.barcodeScanner.message(null);
        }, 1000);
        if (++scans === 10) {
            cordova.plugins.barcodeScanner.hide();
        }
    },
    function(error) {
        clearTimeout(messageTimeout);
        cordova.plugins.barcodeScanner.message('Scanning failed: ' + error);
        setTimeout(function() {
            messageTimeout = cordova.plugins.barcodeScanner.message(null);
        }, 1000);
    }
);
duplicate

Most helpful comment

I agree, continuous scanning is indeed needed for real-world scanning apps. Calling the scan() method recursively works, but it has some lag to it and it decreases performance. Any update on this issue?

All 9 comments

A work around I have used is to recursively call the scan method after every success until the user clicks cancel

I would also welcome this feature. It could for example "scan until user clicks done/back button" and then return results in array.. What do you think?

@Giriton I have just implemented such a workaround. I don't think it's quite as fast or elegant as just leaving the camera open but it does work. On iOS 9.3, the done button returns me to my Web UI, same with a Google Nexus 4 running Android 5.x. My "Samsung Galaxy Tab A" has a weird thing where if I tap the hardware back button to cancel, it closes the camera UI but also triggers a back call in the web ui, in my case either navigating me backwards or dismissing an open modal. So, I need to find a way for the back button, when in the camera UI, to not propagate to the web ui after dismissing the camera UI.

I agree, continuous scanning is indeed needed for real-world scanning apps. Calling the scan() method recursively works, but it has some lag to it and it decreases performance. Any update on this issue?

If anyone is willing to implement it: on Android we're using the same library as the NativeScript plugin which I've added continuous scan support to already. All required changes to the native library are already in place, so it should be relatively straightforward to add this to the Cordova plugin as well.

On iOS the NativeScript plugin uses my custom library, not the same as the one used in the Cordova plugin, so it may be a little harder.

+1

calling scan() recursively isn't a great solution

Duplicate of #69

+1

calling scan() recursively has some lag

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klickagent picture klickagent  路  3Comments

thomas-tran picture thomas-tran  路  9Comments

vespino picture vespino  路  9Comments

Bajranghudda1 picture Bajranghudda1  路  4Comments

brunovinny picture brunovinny  路  6Comments