Mobile Development 10.11 | webMethods Mobile SuiteWeb Help | Using webMethods Mobile Designer | Creating Mobile Application Projects | Coding a Mobile Application | Migrating to the New Run-Time Classes | Using the ImagePicker Class | Capturing Barcodes Using ImagePicker
 
Capturing Barcodes Using ImagePicker
You can use barcodes or QR-codes as a convenient way to get long URLs, configuration data, product codes, etc. into an application. In order to support this, the ImagePicker harnesses the native capabilities of devices to detect barcodes in images.
Note:
For iOS, iOS 11 or greater is required.
Barcodes may be detected in images already held in the device's gallery, using live video from the camera, or using static images captured by the camera. Barcode values detected in the image are returned to a class conforming to IBarcodePickerCallback.
if(use_camera)
{
ImagePicker.scanBarcodeFromCamera(new MyBarcodeCallback());
}
else
{
ImagePicker.scanBarcodeFromGallery(new MyBarcodeCallback());
}
The classMyBarcodeCallback can then be implemented as follows. Note that there may be more than one barcode in the image, so onBarcode() returns an array of String values.
class MyBarcodeCallback implements IBarcodePickerCallback
{
public void onBarcode(String[] barcodes)
{
System.out.println("Got " + barcodes.length + " barcodes.");

for (int i = 0; i < barcodes.length; i++)
{
System.out.println("You scanned : " + barcodes[i]);
}
}

public void onBarcodeFailed(int result, String error)
{
System.out.println("Barcode scanning failed, error code :
" + result + ", with message : " + error);
}
}
Note:
As with other methods in ImagePicker, it is possible that the mobile OS may have backgrounded or closed and re-started your application during the image selection process. This is important to bear in mind when your callback returns.
Furthermore, you can limit the types of barcodes detected using the following code:
//No 2D barcodes, please!
ImagePicker.scanBarcodeFromGallery(new MyBarcodeCallback(),
ImagePicker.BARCODE_TYPE_LINEAR_ALL);