Bringing Barcodes to BlackBerry Applications

How-to

The Barcode Capture API included with BlackBerry® 6 comes with a nifty new feature: The ability for a third-party developer to integrate scanning and generating 1D and 2D barcodes inside their app. It’s really easy, too – take a look at this article in our Developer Resource Center to see a sample app that will generate QR codes, or scan them and open the URL in the browser.

If you have a device running BlackBerry® 6 you can compile the app and start playing around with it right now! If not, you may have noticed the new version of BlackBerry App World ™ (version 2.0) has a “Scan a Barcode” menu option. It’s nominally used to open links to apps in the App World, but it will do any URL encoded in a QR Code. Try this one:

QR Codes, if you have never encountered them before, are a type of 2D barcode. This is in contrast to a 1D barcode like the UPCs you see on most products. The big advantage of 2D barcodes (and QR codes in particular) is that they are easy to scan with a camera and can contain a lot of information. QR codes can hold up to 4296 alphanumeric characters, leaving you plenty of space for URLs or other bits of text data. 1D codes are more difficult to detect, and must be viewed straight on by the camera. This means that on a BlackBerry® Torch™ 9800 smartphone, you actually have to rotate the device into landscape mode to detect them properly. QR codes use those squares in the corner to make it easy to figure out the proper orientation.

They are pretty popular in the mobile space, so if you are interested in doing stuff with barcodes, QR codes are probably the one you want. They aren’t the only kind of barcode available to you as a developer, however – we’ve used the open source ZXing library (pronounced “zebra crossing”) to add support for many different kinds of barcode:

2D
QR Code
Data Matrix
PDF 417

1D
UPC (A and E)
EAN (8 and 13)
Code-39
Code-128
ITF

The full list is always in the BarcodeFormat class. Currently, as per the ZXing library, Data Matrix and PDF 417 support is alpha quality. These, along with the ease of reading – and an already very large mobile presence – make QR codes the best choice for most applications. As I said, the Barcode API in BlackBerry 6 allows the BlackBerry smartphone to generate a QR code for you, but there are also several websites that will help you do that as well (if you want to print them off, for example) such as here.

Finally, you might be interested to know that the com.google.zxing package is actually very powerful, letting you get down into the nitty-gritty barcode data if you want. You can play around with the bit matrix used to generate 2D barcodes, and it also offers a few nifty methods like a Reed-Solomon encoder and decoder.

And don’t forget, even if you don’t need to use QR codes inside your application, with the function already built into BlackBerry App World they are a great way to promote your app. Just make one using your app’s URL in BlackBerry App World, and if a user sees it on a billboard or in a magazine, they can scan it and buy it right away.

Have you had any experience with the Barcode API yet? What did you think of it?

About Paul Bernhardt

I work for BlackBerry on the Developer relations team helping developers write apps in Cascades. I focus on camera, gaming and Unity mostly. My views are my own. In my free time, I'm a hardcore PC gamer and draw D&D maps for fun!

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus