The package contains classes to read barcodes from image data and camera on Andriod device.
There are two ways how to use the SDK within Android application. First and more generic way is to use BarcodeReader class instance. It allow to recognize Barcode from RGB image buffer, for example obtained from JPEG image loaded into BitmapDrawable. To read barcodes directly from camera use BarcodeScanDialog. This is a UI control which use callback notification mechanism to report about newelly recognized Barcode Symbols.
This is a piece of code demonstrate how to recognize barcode from 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 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);
}
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 to call BarcodeScanDialog.hide() 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.