views:

1550

answers:

5

Hi I am developing an application for the android htc hero. I am looking into ways of using the inbuilt camer to read 2D barcodes and extract the string returned from the barcode. I have only recently begun working with the android sdk but I do have a programming background from working on projects with java. I am curious to know what the best way to read the 2D barcode would be. I have some sample applications that read the barcode but they are all .apk files and have no source or library that i can work with. to give you a better idea of what i am trying to accomplish this site allows the generation of 2d barcodes made up of the data you desire here

Any replies would be greatly appreciated.

+2  A: 

I'd look at this open source Android project: http://code.google.com/p/zxing/

mbaird
+7  A: 

Android programs can interact with eachother using intents. Intents are a little like remote procedure calls: you ask the other program for a certain action (e.g. scan a barcode) and the other program will perform this task for you. The result is returned when the task is complete.

If the user has installed the ZXing Barcode Scanner, you can just use an intent to scan a barcode. The Barcode Scanner will then start, let the user scan the code and return the result to you.

More information about this scanner can be found on the Google Code page of this project: http://code.google.com/p/zxing/wiki/ScanningViaIntent

Scharrels
And here's a doc that explains how to programmatically test for an activity that can handle an intent: http://developer.android.com/resources/articles/can-i-use-this-intent.html, and if you want to direct the user to download the Barcode Scanner app, this doc has an overview on the URIs to use: http://developer.android.com/guide/publishing/publishing.html#marketintent
Roman Nurik
A: 

As far as I know for decoding barcodes (apart from the algorithm) you need to know the (relative) widths of white and black bars. For that, you would have to rotate the barcode to a horizontal position and then detect the widths.

(Ok, the ZXIng stuff advised by others outperforms this manual hacking)

ron
That is not necessary: as long as you can make a horizontal line through all the bars, the barcode doesn't have to be horizontal - the bars will be wider in absolute numbers, but the relative widths of bars and spaces will remain unchanged. In other words, you can correctly scan even rotated or skewed barcodes.
Piskvor
A: 

Make sure you identify your barcode format. The Zxing site says it reads Datamatrix format but they are still having difficulty with the Detector at the time of this posting.

Daddyboy
You should try again -- as of a month ago DM works now.
Sean Owen
Thank you. Yes it now works.
Daddyboy
A: 
With Zxing lib, you only code in java language with low performance. if you need high speed, the native code library is the best choice.
I know mobiscans's application use the native code library from http://www.aipsys.com. I haave ever downloaded the applications name mobiscan Datamatrix, and found the speed is very fast and even the blur barcode can be decoded.
godsky
Well, I'd suggest you benchmark it. This "low performance" Java decodes in under 100ms. It's not the bottleneck compared to getting image data from the driver; decoding any faster doesn't help.
Sean Owen