[android] Using ZXing to create an Android barcode scanning app

I've been searching for how to add a barcode scanner to my app. Are there any examples or how can I do this easily?

This question is related to android barcode barcode-scanner zxing

The answer is


Barcode Detection is now available in Google Play services. Code lab of the setup process, here are the api docs, and a sample project.


Using Zxing this way requires a user to also install the barcode scanner app, which isn't ideal. What you probably want is to bundle Zxing into your app directly.

I highly recommend using this library: https://github.com/dm77/barcodescanner

It takes all the crazy build issues you're going to run into trying to integrate Xzing or Zbar directly. It uses those libraries under the covers, but wraps them in a very simple to use API.


You can use this quick start guide http://shyyko.wordpress.com/2013/07/30/zxing-with-android-quick-start/ with simple example project to build android app without IntentIntegrator.


I had a problem with implementing the code until I found some website (I can't find it again right now) that explained that you need to include the package name in the name of the intent.putExtra.

It would pull up the application, but it wouldn't recognize any barcodes, and when I changed it from.

intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

to

intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");

It worked great. Just a tip for any other novice Android programmers.


If you want to include into your code and not use the IntentIntegrator that the ZXing library recommend, you can use some of these ports:

I use the first, and it works perfectly! It has a sample project to try it on.


Using the provided IntentInegrator is better. It allows you to prompt your user to install the barcode scanner if they do not have it. It also allows you to customize the messages. The IntentIntegrator.REQUEST_CODE constant holds the value of the request code for the onActivityResult to check for in the above if block.

IntentIntegrator intentIntegrator = new IntentIntegrator(this); // where this is activity 
intentIntegrator.initiateScan(IntentIntegrator.ALL_CODE_TYPES); // or QR_CODE_TYPES if you need to scan QR

IntentIntegrator.java


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to barcode

NSCameraUsageDescription in iOS 10.0 runtime crash? Package doesn't exist error in intelliJ How to Generate Barcode using PHP and Display it as an Image on the same page Integrating the ZXing library directly into my Android application How to read barcodes with the camera on Android? QR Code encoding and decoding using zxing Using ZXing to create an Android barcode scanning app Free Barcode API for .NET BarCode Image Generator in Java How can I scan barcodes on iOS?

Examples related to barcode-scanner

Barcode scanner for mobile phone for Website in form Integrating the ZXing library directly into my Android application How to read barcodes with the camera on Android? Using ZXing to create an Android barcode scanning app

Examples related to zxing

How to decode a QR-code image in (preferably pure) Python? Integrate ZXing in Android Studio Integrating the ZXing library directly into my Android application QR Code encoding and decoding using zxing Using ZXing to create an Android barcode scanning app