Embedding ZXing in android app Embedding ZXing in android app android android

Embedding ZXing in android app


I had to do exactly what you are being asked to do. It wasn't that easy, but it wasn't too bad either. It was also my very first (commercial or otherwise) Android app.What I did was:

  • Get the ZXing project compiledand running on your machine. Thereis a good tutorial on how to do this here.
  • Adapt this code to suit your needs. I stripped a lot of the project away to just the basic scanner. I then built the rest of my project around it. Here's how to do that.

  • Adapt the CaptureActivity in core to be as simple as possible. All you need is the number returned from the core scanner code. Here's a picture of the structure of my project:

Structure of Adapted ZXing project

  • What you'll find is that you need to Modify 4 files for your modified Activity Class to work. These files are The CameraCaptureActivity class, The CaptureActivityHandler class, and the Decode Thread and Decode handler classes. I've hosted these files here.

  • Take these four files and put them in a copy of your ZXing working project. Remove the original CaptureActivity and the other Original Threads and Handler Classes that you have replaced. (Ignore the CaptureActivityHandlerDemo file, as it was put up there by mistake)

  • Change the package names to match the working ZXing package names. Make sure that your Activity is named the same in all four of these Classes. It might be a good idea to pass in an interface that implements "getHolder" rather than the Activity Class itself.

  • Make sure you have updated your manifest with any changes to your Activity Name. Make sure you have a way of navigating to the activity - perhaps make it the default class in the intent filter area.

  • I have included a layout file for your activity also - it's very simple, but it's all your need to get the scanner up and working. it's called camera_capture.xml

Hopefully this is all you need to get up and running. It's not an easy process and unfortunately I can't give you my entire project as it's a commercial product.

Good Luck!!

PS please post any questions as comments on this answer and I'll do my best to help.


I forked the Barcode Scanner and converted it into a library project, and removed most of the functionality you don't need if you're only scanning barcodes via IntentIntegrator.

The project with instructions is available at https://github.com/embarkmobile/zxing-android-minimal.

It is really easy to include it in your project if you're already using Maven. If not - you can copy the code over to your project, using the approach described by CaspNZ.