Barcode Scanner Libraries for Android

Related tags

SDK barcodescanner
Overview

Project Archived

July 1 2020

This project is no longer maintained. When I first started this project in late 2013 there were very few libraries to help with barcode scanning on Android. But the situation today is much different. We have lots of great libraries based on ZXing and there is also barcode scanning API in Google's MLKit (https://github.com/googlesamples/mlkit). So given the options I have decided to stop working on this project.

Introduction

Android library projects that provides easy to use and extensible Barcode Scanner views based on ZXing and ZBar.

Screenshots

Minor BREAKING CHANGE in 1.8.4

Version 1.8.4 introduces a couple of new changes:

  • Open Camera and handle preview frames in a separate HandlerThread (#1, #99): Though this has worked fine in my testing on 3 devices, I would advise you to test on your own devices before blindly releasing apps with this version. If you run into any issues please file a bug report.
  • Do not automatically stopCamera after a result is found #115: This means that upon a successful scan only the cameraPreview is stopped but the camera is not released. So previously if your code was calling mScannerView.startCamera() in the handleResult() method, please replace that with a call to mScannerView.resumeCameraPreview(this);

ZXing

Installation

Add the following dependency to your build.gradle file.

repositories {
   jcenter()
}
implementation 'me.dm7.barcodescanner:zxing:1.9.13'

Simple Usage

1.) Add camera permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

2.) A very basic activity would look like this:

public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
        setContentView(mScannerView);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        Log.v(TAG, rawResult.getText()); // Prints scan results
        Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}

Please take a look at the zxing-sample project for a full working example.

Advanced Usage

Take a look at the FullScannerActivity.java or FullScannerFragment.java classes to get an idea on advanced usage.

Interesting methods on the ZXingScannerView include:

// Toggle flash:
void setFlash(boolean);

// Toogle autofocus:
void setAutoFocus(boolean);

// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);

// Specify the cameraId to start with:
void startCamera(int cameraId);

Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.

For HUAWEI mobile phone like P9, P10, when scanning using the default settings, it won't work due to the "preview size", please adjust the parameter as below:

mScannerView = (ZXingScannerView) findViewById(R.id.zx_view);

// this paramter will make your HUAWEI phone works great!
mScannerView.setAspectTolerance(0.5f);

Supported Formats:

BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417

ZBar

Installation

Add the following dependency to your build.gradle file.

repositories {
   jcenter()
}
implementation 'me.dm7.barcodescanner:zbar:1.9.13'

Simple Usage

1.) Add camera permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

2.) A very basic activity would look like this:

public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler {
    private ZBarScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZBarScannerView(this);    // Programmatically initialize the scanner view
        setContentView(mScannerView);                // Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        Log.v(TAG, rawResult.getContents()); // Prints scan results
        Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)

        // If you would like to resume scanning, call this method below:
        mScannerView.resumeCameraPreview(this);
    }
}

Please take a look at the zbar-sample project for a full working example.

Advanced Usage

Take a look at the FullScannerActivity.java or FullScannerFragment.java classes to get an idea on advanced usage.

Interesting methods on the ZBarScannerView include:

// Toggle flash:
void setFlash(boolean);

// Toogle autofocus:
void setAutoFocus(boolean);

// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);

Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.

Supported Formats:

BarcodeFormat.PARTIAL
BarcodeFormat.EAN8
BarcodeFormat.UPCE
BarcodeFormat.ISBN10
BarcodeFormat.UPCA
BarcodeFormat.EAN13
BarcodeFormat.ISBN13
BarcodeFormat.I25
BarcodeFormat.DATABAR
BarcodeFormat.DATABAR_EXP
BarcodeFormat.CODABAR
BarcodeFormat.CODE39
BarcodeFormat.PDF417
BarcodeFormat.QR_CODE
BarcodeFormat.CODE93
BarcodeFormat.CODE128

Rebuilding ZBar Libraries

mkdir some_work_dir
cd work_dir
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz

Patch the localcharset.c file: vim libiconv-1.14/libcharset/lib/localcharset.c

On line 48, add the following line of code:

#undef HAVE_LANGINFO_CODESET

Save the file and continue with steps below:

cd libiconv-1.14
./configure
cd ..
hg clone http://hg.code.sf.net/p/zbar/code zbar-code
cd zbar-code/android
android update project -p . -t 'android-19'

Open jni/Android.mk file and add fPIC flag to LOCAL_C_FLAGS. Open jni/Application.mk file and specify APP_ABI targets as needed.

ant -Dndk.dir=$NDK_HOME  -Diconv.src=some_work_dir/libiconv-1.14 zbar-clean zbar-all

Upon completion you can grab the .so and .jar files from the libs folder.

Credits

Almost all of the code for these library projects is based on:

  1. CameraPreview app from Android SDK APIDemos
  2. The ZXing project: https://github.com/zxing/zxing
  3. The ZBar Android SDK: https://github.com/ZBar/ZBar/tree/master/android (Previously: http://sourceforge.net/projects/zbar/files/AndroidSDK/)

Contributors

https://github.com/dm77/barcodescanner/graphs/contributors

License

License for code written in this project is: Apache License, Version 2.0

License for zxing and zbar projects is here:

Comments
  • Exception: java.lang.RuntimeException: autoFocus failed

    Exception: java.lang.RuntimeException: autoFocus failed

    Hi, the barcodescanner initially works fine but after trying to auto focus two to three times i get a RuntimeException: autoFocus failed:

    java.lang.RuntimeException: autoFocus failed
                at android.hardware.Camera.native_autoFocus(Native Method)
                at android.hardware.Camera.autoFocus(Camera.java:975)
                at me.dm7.barcodescanner.core.CameraPreview$1.run(CameraPreview.java:196)
                at android.os.Handler.handleCallback(Handler.java:730)
                at android.os.Handler.dispatchMessage(Handler.java:92)
                at android.os.Looper.loop(Looper.java:213)
                at android.app.ActivityThread.main(ActivityThread.java:5225)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
                at dalvik.system.NativeStart.main(Native Method)
    
    

    any idea how to fix that? Thanks Criss

    opened by crissk047 37
  • 1.7.1 : Zbar example basic : autofocus failed

    1.7.1 : Zbar example basic : autofocus failed

    Hello,

    In the last version (before it works). When I do a simple activity like a exemple in the home page of your project I have a error :

    java.lang.RuntimeException: autoFocus failed at android.hardware.Camera.native_autoFocus(Native Method) at android.hardware.Camera.autoFocus(Camera.java:1299) at me.dm7.barcodescanner.core.CameraPreview$1.run(CameraPreview.java:245) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:211) at android.app.ActivityThread.main(ActivityThread.java:5317) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

    Thanks

    opened by Paul75 30
  • Bug with Zbar

    Bug with Zbar

    Anyone else have this problem with the newest version of zbar ?

    java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/de.xxx.xxx-2/lib/arm/libiconv.so: has text relocations
    
    opened by larsdecker 25
  • Add option for scaling the camera preview

    Add option for scaling the camera preview

    Whether or not to scale the preview is defined by the boolean resource cameraPreviewShouldFillView. Default is false, but can be overridden by applications by defining

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <bool name="cameraPreviewShouldFillView">true</bool>
    </resources> 
    

    This should not cause problems due to stretching, as aspect ratio is maintained, by not wrapping the preview in a RelativeLayout (keeping FrameLayout as parent, which clips/crops).

    opened by xolan 23
  • An error occured while connecting to camera

    An error occured while connecting to camera

    I'm getting W/CameraBase﹕ An error occurred while connecting to camera when the app opens up, a black screen with the red scan line appears. What's causing this? I'm using Nexus 4 with Android Lollipop 5.0

    bug 
    opened by RonCan 18
  • E/ZBarScannerView: java.lang.RuntimeException: Camera is being used after Camera.release() was called

    E/ZBarScannerView: java.lang.RuntimeException: Camera is being used after Camera.release() was called

    I just open scanner simple activity and click back button then it throws this error "E/ZBarScannerView: java.lang.RuntimeException: Camera is being used after Camera.release() was called" p.s. My phone is Huawei P9.

    wontfix 
    opened by BigWattanachai 17
  • Scanner does not work in portrairt mode

    Scanner does not work in portrairt mode

    First of all thanks for this amazing library, really made my android developer life easier :) I have some problem with the last version of the app (1.9.5). I basically copied and pasted the SampleScanner example provided and the scanner works fine only in landscape mode, while in portrait mode the result handler is not even called. I have a galaxy s5 mini with Android 6.0 installed. Notice that I do not have the same problem if the dependency I add to gradle is 1.9.4.

    opened by dovidio 16
  • White screen in a fragment (zbar barcode scanning)

    White screen in a fragment (zbar barcode scanning)

    Thanks for a nice library. I have an application with old version of this library. I added a fragment to activity as usual, started camera similar to https://github.com/dm77/barcodescanner/blob/master/zbar-sample/src/main/java/me/dm7/barcodescanner/zbar/sample/SimpleScannerFragment.java. I saw an image and could get a EAN_13 code. Then closed the fragment. The second time I opened it I saw a black screen instead of camera preview. Sometimes after several efforts camera worked again. Also a standard photo application wrote that the camera is in use. When I changed a fragment to activity, everything worked right. Then I updated a library to v. 1.9. Instead of the black screen I got white. It appears on the second opening of the fragment. Third, fourth, etc. times don't change the behaviour. Again, changing to activity reuses camera well. A device is Samsung Galaxy S4 running Android 5.0.1. Also tested on another Android 5.0 device.

    Update

    After one day of testing scanning with an activity I noticed that in seldom cases the activity also shows white screen.

    wontfix 
    opened by CoolMind 14
  • Crashes on Samsung S phones

    Crashes on Samsung S phones

    java.lang.RuntimeException: getParameters failed (empty parameters) at android.hardware.Camera.native_getParameters(Native Method) at android.hardware.Camera.getParameters(Camera.java:1952) at me.dm7.barcodescanner.core.CameraUtils.isFlashSupported(CameraUtils.java:47) at me.dm7.barcodescanner.core.BarcodeScannerView.setFlash(BarcodeScannerView.java:252) at me.dm7.barcodescanner.core.BarcodeScannerView.setupCameraPreview(BarcodeScannerView.java:189) at me.dm7.barcodescanner.core.CameraHandlerThread$1$1.run(CameraHandlerThread.java:31) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

    wontfix 
    opened by tibigeorgescu90 12
  • java.lang.RuntimeException: cancelAutoFocus failed in onPause()

    java.lang.RuntimeException: cancelAutoFocus failed in onPause()

    Hi, got this Issue after upgrading Andoid OS in my ActivityCodeScanner in method onPause():

    @Override public void onPause() { super.onPause(); mScannerView.stopCamera(); }

    Where mScannerView is:

    @Override public void onCreate(Bundle state) { super.onCreate(state); mScannerView = new ZXingScannerView(this); setContentView(mScannerView); .............................................. }

    My Device is Huawei Honor 4x (Android 6.0)

    StackTrace: java.lang.RuntimeException: cancelAutoFocus failed at android.hardware.Camera.native_cancelAutoFocus(Native Method) at android.hardware.Camera.cancelAutoFocus(Camera.java:1476) at me.dm7.barcodescanner.core.CameraPreview.stopCameraPreview(CameraPreview.java:109) at me.dm7.barcodescanner.core.BarcodeScannerView.stopCamera(BarcodeScannerView.java:85) at com.android.app.mysuperapp.ui.ActivityCodeScanner.onPause(ActivityCodeScanner.java:57) at android.app.Activity.performPause(Activity.java:6495) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1322) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3398) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3371) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3346) at android.app.ActivityThread.access$1100(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5546) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)

    What other information need to provide?

    opened by whizzzkey 12
  • Valid QR Code not being read.

    Valid QR Code not being read.

    I have a valid QR code that gets read in iOS (using a different library) but fails to be read in Android. I have followed the example verbatim and still not getting it. Please advise -- Is there anything I'm doing wrong? Perhaps in generating the QR code? But it works in iOS?

    I have attached my QR code below:

    0bb5668edbb67eb

    opened by kalvish21 12
Releases(1.9.8)
Owner
Dushyanth
Dushyanth
Sdk-android - SnapOdds Android SDK

Documentation For the full API documentation go to https://snapodds.github.io/sd

Snapodds 0 Jan 30, 2022
AWS SDK for Android. For more information, see our web site:

AWS SDK for Android For new projects, we recommend interacting with AWS using the Amplify Framework. The AWS SDK for Android is a collection of low-le

AWS Amplify 976 Dec 29, 2022
Accept PayPal and credit cards in your Android app

Important: PayPal Mobile SDKs are Deprecated. The APIs powering them will remain operational long enough for merchants to migrate, but the SDKs themse

PayPal 802 Dec 22, 2022
Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.

LandscapeVideoCamera Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to

Jeroen Mols 1.2k Dec 29, 2022
Library for Android In-App Billing (Version 3+)

Checkout (Android In-App Billing Library) Description Checkout is an implementation of Android In-App Billing API (v3+). Its main goal is to make inte

Sergey Solovyev 1k Nov 26, 2022
Countly Product Analytics Android SDK

Countly Android SDK We're hiring: Countly is looking for Android SDK developers, full stack devs, devops and growth hackers (remote work). Click this

Countly Team 648 Dec 23, 2022
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Applozic 659 May 14, 2022
Evernote SDK for Android

Evernote SDK for Android version 2.0.0-RC4 Evernote API version 1.25 Overview This SDK wraps the Evernote Cloud API and provides OAuth authentication

Evernote 424 Dec 9, 2022
SocialAuth repository which contains socialauth android version and samples

SocialAuth Android is an Android version of popular SocialAuth Java library. Now you do not need to integrate multiple SDKs if you want to integrate y

3Pillar Global Open Source 318 Dec 30, 2022
Android library project for providing multiple image selection from the device.

PolyPicker Android library project for selecting/capturing multiple images from the device. Result Caution! Eclipse library project structure has been

JW 407 Dec 27, 2022
Air Native Extension (iOS and Android) for the Facebook mobile SDK

Air Native Extension for Facebook (iOS + Android) This is an AIR Native Extension for the Facebook SDK on iOS and Android. It has been developed by Fr

Freshplanet 219 Nov 25, 2022
Donations library for Android. Supports Google Play Store, Flattr, PayPal, and Bitcoin

Android Donations Lib Android Donations Lib supports donations by Google Play Store, Flattr, PayPal, and Bitcoin. It is used in projects, such as Open

Sufficiently Secure 346 Jan 8, 2023
Android library that provides for multiple image selection.

#MultipleImageSelect An android library that allows selection of multiple images from gallery. It shows an initial album (buckets) chooser and then im

Darshan Dorai 299 Nov 14, 2022
Microsoft Services SDKs for Android produced by MS Open Tech.

Important: This preview SDK has been deprecated and is no longer being maintained. We recommend that you use Microsoft Graph and the associated Micros

Office Developer 222 Dec 1, 2022
A clustering library for the Google Maps Android API v2

DEPRECATED Don't use this. The Maps v3 SDK handles markers. That with a few other cool utilities make this library obsolete! Clusterkraf A clustering

Ticketmaster Mobile Studio 258 Nov 28, 2022
Android Chat SDK built on Firebase

Chat21 is the core of the open source live chat platform Tiledesk.com. Chat21 SDK Documentation Features With Chat21 Android SDK you can: Send a direc

Chat21 235 Dec 2, 2022
Amazon S3 multipart file upload for Android, made simple

Simpl3r Amazon S3 multipart file upload for Android, made simple This library provides a simple high level Android API for robust and resumable multip

Jeff Gilfelt 182 Nov 15, 2022
Liquid SDK (Android)

Liquid Android SDK Quick Start to Liquid SDK for Android This document is just a quick start introduction to Liquid SDK for Android. We recommend you

Liquid 17 Nov 12, 2021
Horoscope API for android to get the horoscope according to the sunsign

Horoscope-API. Simple Java API to get the horoscope according to the sunsign. Contents Features Implementation API Usage To-dos Credits License Featur

TheBotBox 34 Dec 2, 2022