Package sdt.brc.android

The package contains classes to read barcodes from image data and camera on Android device.

See:
          Description

Interface Summary
OnRecognitionListener Interface for receiving events about new recognized barcodes.
 

Class Summary
BarcodeReader The Barcode engine for reading barcodes from image
BarcodeReaderResult Recognized Barcode Information.
BarcodeReaderUtil Android helper class.
BarcodeScanDialog The Android popup Dialog which preview the camera and reads barcodes from it.
 

Package sdt.brc.android Description

The package contains classes to read barcodes from image data and camera on Android device.

There are two ways how to use the SDK within Android application. First and more generic way is to use BarcodeReader class instance. The class provide methods to recognize barcodes from RGB image buffer, for example, obtained from JPEG image loaded into Bitmap. To scan barcodes directly from camera you should use BarcodeScanDialog. This class is a UI control which use callback notification mechanism to report about newly recognized barcode symbols.

Reading barcodes from android Image object

This is a piece of code demonstrating how to read barcode symbol from sample JPEG file stored on SD card.

        //Obtain file stored on SD Card
        String sdcardPath = Environment.getExternalStorageDirectory().toString();
        String imageFullPath = sdcardPath +  "/test/Ean13.jpg";

        //Read and decode JPEG image
        Bitmap bitmap = BitmapFactory.decodeFile(imageFullPath);
        
        //Allocate Buffer for storing RGB image data
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int rgbBuffer[] = new int[width * height];
        
        //Finally obtain RGB pixels.
        bitmap.getPixels(rgbBuffer, 0, width, 0, 0, width, height);

        //Initialize Barcode reader. Pass a valid developer key as a second parameter
        BarcodeReader barcodeReader = new BarcodeReader(getApplicationContext(), "Developer license key must be to here.");
        barcodeReader.setReadInputTypes(BarcodeReader.SDTBARCODE_ALL_1D);
        barcodeReader.readRGBBufferInt(rgbBuffer, width, height) ;
        if(barcodeReader.getResultsCount() > 0) {
            //Read first recognized symbol
            BarcodeReaderResult result = barcodeReader.getResultAt(0);
            Toast.makeText(getApplicationContext(), result.getValue(), Toast.LENGTH_SHORT);
        }

Reading barcodes from android camera device

To scan barcode from android camera within your application is pretty easy using BarcodeScanDialog class. All what you need is to create BarcodeScanDialog instance within your Activity, assign the OnRecognitionListener callback object to it and call BarcodeScanDialog.show() method. You should see the camera preview dialog now :

Once the barcode will be recognized, the OnRecognitionListener.onRecognitionResults() callback method will be called to inform your application about recognized barcode symbols.

At this point you can close the recognition dialog by calling BarcodeScanDialog.hide() or continue to show the dialog if needed.

Note, that you must call BarcodeScanDialog.hide() and BarcodeScanDialog.dismiss() from your activity onStop() method. Otherwise your camera device will remain locked. For more detailed tutorial please refer to Barcode Reader SDK for Android. Read Barcodes from Android camera inside your java application.