Code Monkey home page Code Monkey logo

barcode-scanner's Introduction

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.

compile 'me.dm7.barcodescanner:zxing:1.9'

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] (https://github.com/dm77/barcodescanner/tree/master/zxing-sample) project for a full working example.

Advanced Usage

Take a look at the [ScannerActivity.java] (https://github.com/dm77/barcodescanner/blob/master/zxing/sample/src/main/java/me/dm7/barcodescanner/zxing/sample/ScannerActivity.java) or [ScannerFragment.java] (https://github.com/dm77/barcodescanner/blob/master/zxing/sample/src/main/java/me/dm7/barcodescanner/zxing/sample/ScannerFragment.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.

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.

compile 'me.dm7.barcodescanner:zbar:1.9'

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] (https://github.com/dm77/barcodescanner/tree/master/zbar/sample) project for a full working example.

Advanced Usage

Take a look at the [ScannerActivity.java] (https://github.com/dm77/barcodescanner/blob/master/zbar/sample/src/main/java/me/dm7/barcodescanner/zbar/sample/ScannerActivity.java) or [ScannerFragment.java] (https://github.com/dm77/barcodescanner/blob/master/zbar/sample/src/main/java/me/dm7/barcodescanner/zbar/sample/ScannerFragment.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.QRCODE
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: http://sourceforge.net/projects/zbar/files/AndroidSDK/

Contributors

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

License

Apache License, Version 2.0

barcode-scanner's People

Contributors

dm77 avatar oleggreen avatar xolan avatar mbergou avatar rking788 avatar furedal avatar cujo avatar divankov avatar donnfelker avatar guiruiz avatar lolobosse avatar plastiv avatar se-bastiaan avatar timmmm avatar dmo60 avatar vpas avatar vivekkiran avatar wellguimaraes avatar yarikx avatar

Watchers

James Cloos avatar Sathish Gadde avatar

barcode-scanner's Issues

Error occurring while build

  • What went wrong:
    A problem occurred configuring root project 'BarCode-Scanner-master'.

Could not resolve all artifacts for configuration ':classpath'.
Could not find org.jetbrains.trove4j:trove4j:20160824.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://maven.google.com/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://maven.google.com/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
Required by:
project : > com.android.tools.build:gradle:3.6.3 > com.android.tools.build:builder:3.6.3 > com.android.tools:sdk-common:26.6.3

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.