Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Add config option to only scan a specific Barcode type #14

Closed
SunboX opened this issue Jun 22, 2015 · 12 comments
Closed

Add config option to only scan a specific Barcode type #14

SunboX opened this issue Jun 22, 2015 · 12 comments

Comments

@SunboX
Copy link
Contributor

SunboX commented Jun 22, 2015

Add a option to only scan (for example) EAN_13 Barcodes and ignore all others. This should speed up Barcode recognition and should avoid false positives.

@newebug
Copy link

newebug commented Jun 29, 2015

Yes, we need this option also, and an option to determine landscape mode or portait.

@SunboX
Copy link
Contributor Author

SunboX commented Jun 29, 2015

👍

@nofxx
Copy link

nofxx commented Jul 3, 2015

+1 Needs to include only QR too.

@javifr
Copy link

javifr commented Jul 3, 2015

+10000

@jschmiede
Copy link

+1

@nofxx
Copy link

nofxx commented Jul 4, 2015

I've found it, undocumented but working on android and iOS!! Very nice!

https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/android/LibraryProject/src/com/google/zxing/client/android/Intents.java#L44

The plugin applies options with intentScan.putExtra on BarcodeScanner.java.

    /**
     * By default, sending this will decode all barcodes that we understand. However it
     * may be useful to limit scanning to certain formats. Use
     * {@link android.content.Intent#putExtra(String, String)} with one of the values below.
     *
     * Setting this is effectively shorthand for setting explicit formats with {@link #FORMATS}.
     * It is overridden by that setting.
     */
    public static final String MODE = "SCAN_MODE";
    public static final String PRODUCT_MODE = "PRODUCT_MODE";
    public static final String ONE_D_MODE = "ONE_D_MODE";
    public static final String QR_CODE_MODE = "QR_CODE_MODE";
    public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE";

    /**
     * Comma-separated list of formats to scan for. The values must match the names of
     * {@link com.google.zxing.BarcodeFormat}s, e.g. {@link com.google.zxing.BarcodeFormat#EAN_13}.
     * Example: "EAN_13,EAN_8,QR_CODE". This overrides {@link #MODE}.
     */
    public static final String FORMATS = "SCAN_FORMATS";

Did suffice my needs: only QR.

Javascript code:

cordova.plugins.barcodeScanner.scan(good_scan, bad_scan, {'SCAN_MODE': 'QR_CODE_MODE'})

@nofxx
Copy link

nofxx commented Jul 4, 2015

Ok, there's a lil issue. Options is implemented totally different on iOS.
That should be why it's undocumented.
On iOS there's actually only one option, that you can pass by text: overlayXib.

It's very easy to make this issue work as I said earlier ust commenting out:
First this overlay (the argument will get a json).

https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/ios/CDVBarcodeScanner.mm#L151

And comment decodeHints you don't want.

https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/ios/CDVBarcodeScanner.mm#L505
Now, just lost the last 4 hours of life with objective C. In a hope it wasn't in vain, to receive the json nicely: (inside CDVBarcodeScanner.mm scan:)

    NSDictionary *opts = [command.arguments objectAtIndex:0];

    NSString *overlayXib = [opts valueForKey:@"overlayXib"];
    NSString *scanMode = [opts valueForKey:@"SCAN_MODE"];

    NSLog(@"options mode %@", opts);

That works nice, so you we can pass the same options in iOS and Android in the view:

cordova.plugins.barcodeScanner.scan(good_scan, bad_scan, {'SCAN_MODE': 'QR_CODE_MODE', 'XIB_WHATEVER})

What my limited obj c knowledge doesn't now is how to pass that scanMode nsstring to the hints.
Add a lot of IF's ??

I've also changed the flip camera to flash. Going to post the link soon, clean up.

@ghost
Copy link

ghost commented Oct 23, 2015

@nofxx Please update. I'm looking for a tut to change flip to flash.

@nofxx
Copy link

nofxx commented Oct 24, 2015

@Fyod umcanto@5c19c10

I should have commited styling apart, but anyways devs here should be linting the code in the first place ;)

@BiswasKhayargoli
Copy link

Hi guys,
Can you help me with the problem, I too want to scan only the qr codes and I did the following
Intent intentScan = new Intent(SCAN_INTENT);
intentScan.putExtra("SCAN_MODE", QR_CODE_MODE);

But, it is not working, it still scans barcodes along with qr codes. What am I doing wrong here? If possible can you provide an example code to meet my requirements. Thank you

@EddyVerbruggen
Copy link
Collaborator

With version 5.0.0 you can now also pass a formats param see the readme for an example (don't add spaces between the formats).

@lock
Copy link

lock bot commented Jun 8, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

8 participants