Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
My Carrier: MOVISTAR Venezuela

Scanning Barcodes

[ Edited ]

I am using following code but only scans qrcode not any of the others like code 39

        private void scanBarcode() {
                _barcodeScreen = null; // If we haven't scanned before, we will set up
                                                                // our barcode scanner
                if (_barcodeScreen == null) {

                        // First we create a hashtable to hold all of the hints that we can
                        // give the API about how we want to scan a barcode to improve speed
                        // and accuracy.
                        Hashtable hashtable = new Hashtable();
                        Vector formats = new Vector(20);
                        formats.addElement(BarcodeFormat.QR_CODE);
                        formats.addElement(BarcodeFormat.PDF417);
                        formats.addElement(BarcodeFormat.CODE_128);
                        formats.addElement(BarcodeFormat.CODE_39);
                        formats.addElement(BarcodeFormat.DATAMATRIX);
                        formats.addElement(BarcodeFormat.EAN_13);
                        formats.addElement(BarcodeFormat.EAN_8);
                        formats.addElement(BarcodeFormat.RSS14);
                        formats.addElement(BarcodeFormat.UPC_EAN_EXTENSION);
                        hashtable.put(DecodeHintType.POSSIBLE_FORMATS, formats);
                        // hashtable.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

                        BarcodeDecoder decoder = new BarcodeDecoder(hashtable);

                       
                        try {
                                _scanner = new BarcodeScanner(decoder,
                                                new MyBarcodeDecoderListener());
                                _barcodeScreen = new MyBarcodeScannerViewScreen(_scanner);

                        } catch (Exception e) {
                                log("No se pudo inicializar el scanner: " + e);
                                return;
                        }
                }

                // If we get here, all the barcode scanning infrastructure should be set
                // up, so all we have to do is start the scan and display the viewfinder
                try {
                        _scanner.startScan();
                        UiApplication.getUiApplication().pushScreen(_barcodeScreen);
                } catch (Exception e) {
                        log("No se pudo iniciar scan: " + e);
                        onClose();

                }

        }

 

llowing code to scan barcodes it works fine with qrcode but not with the otres what i am missing help pls

Please use plain text.
Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Scanning Barcodes

What device/OS are you testing on? If you don't have one with an autofocus camera, it will be very difficult to scan 1D codes.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.
Developer
Dionysus
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: Scanning Barcodes

Is there any specific reason why you're commenting out the hint type "TRY_HARDER"?

 

Also, what happens when you scan other barcodes? What's happening in "MyBarcodeDecoderListener"?

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
My Carrier: MOVISTAR Venezuela

Re: Scanning Barcodes

my device 9900 bold os 7.1 also tryed in simulaor no efect 

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
My Carrier: MOVISTAR Venezuela

Re: Scanning Barcodes

this i my code 

private class MyBarcodeDecoderListener implements BarcodeDecoderListener {

                public void barcodeDecoded(final String rawText) {

                        // First pop the viewfinder screen off of the stack so we can see
                        // the main app
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
                                public void run() {

                                        UiApplication.getUiApplication().popScreen(_barcodeScreen);

                                }
                        });

                        // We will use a StringBuffer to create our message as every String
                        // concatenation creates a new Object
                        final StringBuffer message = new StringBuffer(
                                        "Desea abrir el browser para \"");
                        message.append(rawText);
                        message.append("\"?");
                        log(message.toString());
                        _barcodeScreen.invalidate();

                        // Prompt the user to open the browser pointing at the URL we
                        // scanned
                        UiApplication.getUiApplication().invokeLater(new Runnable() {
                                public void run() {
                                        if (Dialog.ask(Dialog.D_YES_NO, message.toString()) == Dialog.YES) {

                                                // Get the default sessionBrowserSession
                                                BrowserSession browserSession = Browser
                                                                .getDefaultSession();
                                                // Launch the URL
                                                browserSession.displayPage(rawText);
                                        } else { // cerrar scanner

                                        }

                                }
                        });
                }

        }

 tks rsoler

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
My Carrier: MOVISTAR Venezuela

Re: Scanning Barcodes

in the simulator debug window

[ 298,484] CAM: getLastAsyncApiResult: Success
[ 298,484] CamController.onCameraFrameTransferEnqueueComplete : ApiResult : status=0; state=5; handle =12432245; opCode=20; userId=18
[ 298,492] CamGetFTFrame: bmp type=17408, size=614400
[ 298,492] CopyYuvData: VF frame bmp w=640,h=480,s=640
[ 304,804] CameraFrameTransferEnqueue img buf=614400
[ 304,898] CAM:User Id:18

and keeps same results how to debug more where is the error

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
My Carrier: MOVISTAR Venezuela

Re: Scanning Barcodes

simulator screen snapshot

9900-01.png

Please use plain text.