GithubHelp home page GithubHelp logo

hardmankb / zbarscanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dm77/zbarscanner

0.0 1.0 0.0 1.22 MB

This is an Android library project that simplifies the usage of the ZBar SDK for scanning bar codes from within your Android application.

zbarscanner's Introduction

This is an Android library project that simplifies the usage of ZBar Android SDK (http://sourceforge.net/projects/zbar/files/AndroidSDK/) for scanning bar codes from within your Android application.

How to use?

  1. Download this project and add it as a library project to your existing Android app.
  2. Open the AndroidManifest.xml file in your project and add these lines under the manifest element:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
  1. Within the application element, add the activity declartion:
<activity android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"`
            android:screenOrientation="landscape"
            android:label="@string/app_name" />
  1. Now from inside your Android application, you can launch the ZBarScanner from any activity using this intent:
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);

To receive the results of the SCAN, add this method to your activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{    
    if (resultCode == RESULT_OK) 
    {
        // Scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT)
        // Type of the scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE)
        Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, "Scan Result Type = " + data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE), Toast.LENGTH_SHORT).show();
        // The value of type indicates one of the symbols listed in Advanced Options below.
    } else if(resultCode == RESULT_CANCELED) {
        Toast.makeText(this, "Camera unavailable", Toast.LENGTH_SHORT).show();
    }
}

Advanced Options

If you are interested in scanning only QR codes, you can specify the SCAN mode in the intent as shown below:

Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);

You can pass an array or integers for SCAN_MODES. The exact values are specified in net.sourceforge.zbar.Symbol class:

public static final int NONE = 0;
public static final int PARTIAL = 1;
public static final int EAN8 = 8;
public static final int UPCE = 9;
public static final int ISBN10 = 10;
public static final int UPCA = 12;
public static final int EAN13 = 13;
public static final int ISBN13 = 14;
public static final int I25 = 25;
public static final int DATABAR = 34;
public static final int DATABAR_EXP = 35;
public static final int CODABAR = 38;
public static final int CODE39 = 39;
public static final int PDF417 = 57;
public static final int QRCODE = 64;
public static final int CODE93 = 93;
public static final int CODE128 = 128;

If you do not specify scan_modes, the scanner processes all the above listed types.

But if you are interested in QRCodes and ISBN, you would setup the intent as follows:

Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE, Symbol.ISBN10, Symbol.ISBN13});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);

Example app

There is a ZBarScannerDemo app in the examples folder which demonstrates the use of this library.

Tests

I have tested the scanner functionality on these devices without any issues so far:

  • Motorola Droid running Android 2.2.3
  • HTC Thunderbolt running Android 2.3.4
  • Samsung Galaxy Nexus running Android 4.0.4

###Credits Almost all of the code for this library project has been taken from these two places:

  1. CameraPreview app from Android SDK APIDemos
  2. The ZBar Android SDK: http://sourceforge.net/projects/zbar/files/AndroidSDK/

###License MIT

zbarscanner's People

Contributors

dm77 avatar joneswah avatar tmay avatar

Watchers

 avatar

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.