17

Can someone tell me if creating barcode scanner app (for Android) is difficult? Is OpenCV library good start? Where can I find algorithm which clearly explains how to read barcodes? I will appreciate all good materials about this topic!

Thanks in advance!

1
  • 1
    The ZXing library is able to scan barcodes on Android. That might be a starting point.
    – Codo
    Commented Nov 4, 2011 at 12:44

4 Answers 4

26

The ZXing project provides a standalone barcode reader application which — via Android's intent mechanism — can be called by other applications who wish to integrate barcode scanning.

The easiest way to do this is to call the ZXing SCAN Intent from your application, like this:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

Pressing the button linked to mScan would launch directly into the ZXing barcode scanner screen (or crash if ZXing isn't installed). Once a barcode has been recognised, you'll receive the result in your Activity, here in the contents variable.

To avoid the crashing and simplify things for you, ZXing have provided a utility class which you could integrate into your application to make the installation of ZXing smoother, by redirecting the user to the Android Market if they don't have it installed already.

Finally, if you want to integrate barcode scanning directly into your application without relying on having the separate ZXing application installed, well then it's an open source project and you can do so! :)

10

You can use the existing Zebra Crossing barcode scanner for Android, available at: http://code.google.com/p/zxing/. Typically the idea is that you would invoke it via intents, like in the example here: http://code.google.com/p/zxing/wiki/ScanningViaIntent.

2
  • Let's say, I don't want to use such advanced library which do everything for me.
    – Ziem
    Commented Nov 4, 2011 at 12:52
  • 2
    Unfortunately this library is not particularly friendly to being used as just a library jar file that you include in your application, but you can still 'repackage' it manually and try to use just the parts that you need/want. However, as I said, it's mainly meant to be used via intents and it's a bit harder to 'embed' it into your app. Perhaps somebody will have a different suggestion.
    – ivantod
    Commented Nov 4, 2011 at 12:54
6

Zebra Crossing is the best documented java 1D or 2D barcode decoder or encoder around. Lots of people use it, and it's become the de facto standard for android. There's a healthy buzz about it on here too.

RedLaser has an api, but you'll have to pay if you use it in production. When I tried it out, I didn't find it to be a spectacular improvement over Zebra Crossing. Certainly not for the price.

jjil does barcodes but there are only 3 committers on the project, and I've never used it myself so I don't know what to tell you about it. Its source is certainly readable.

Once you start reading, you'll find readers are tricky things to implement due to blurry images, noise, distortion, weird angles, and so forth. So if you want something reliable, you probably want to go with a community-maintained library.

1
  • Now in 2024 nothing mentioned isn't alive
    – horvoje
    Commented May 11 at 19:24
5

You can use zbar library. Download it from: http://sourceforge.net/projects/zbar/files/AndroidSDK/

I think this is more fast and accurate than zxing.

1
  • Can u help me. With my question please
    – AMH
    Commented Mar 16, 2015 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.