Coder Social home page Coder Social logo

promptus / zxing-android-minimal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from journeyapps/zxing-android-embedded

18.0 27.0 9.0 8.41 MB

Port of the ZXing Android application as a minimal Android library project, for embedding in other Android applications.

License: Apache License 2.0

Groovy 1.94% Java 97.85% Shell 0.20%

zxing-android-minimal's Introduction

ZXing Android Minimal

This is a port of the ZXing Android Barcode Scanner application as a minimal Android library project, for embedding in other Android applications. This is not affiliated with the official ZXing project.

Generally it is recommended to scan a barcode via intents. There are however some cases in which it is not feasible:

  • Your users cannot install the Barcode Scanner application.
  • You need to customise the barcode scanning logic.
  • You need to customise the UI.

In these cases, this library may be more suitable.

Adding aar dependency with Gradle

Add the following to your build.gradle file:

repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

dependencies {
    // Supports Android 4.0.3 and later (API level 15)
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'

    // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
    // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
    compile 'com.embarkmobile:zxing-android-legacy:2.0.0@aar'

    // Convenience library to launch the scanning and encoding Activities.
    // It automatically picks the best scanning library from the above two, depending on the
    // Android version and what is available.
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'

    // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
    // This mostly affects encoding, but you should test if you plan to support these versions.
    // Older versions e.g. 2.2 may also work if you need support for older Android versions.
    compile 'com.google.zxing:core:3.0.1'
}

What's the difference between zxing-android-minimal and zxing-android-legacy?

The official ZXing Barcode Scanner application dropped support for older Android versions, and newer releases only support Android 4.0.3 and newer. If you install it on an older Android version from the Play Store, you will get an older version of the Barcode Scanner.

In order to keep up to date with the latest changes and improvements from the official project, we need to do the same. However, many applications still need to support older Android versions.

To cater for these applications, we have two libraries:

  1. zxing-android-minimal - This corresponds to the latest Barcode Scanner version.
  2. zxing-android-legacy - This corresponds to version 2.2 of the ZXing project - the latest version that supported Android 2.2.

zxing-android-minimal uses a zxing prefix for all its resources, while zxing-android-legacy uses a zxinglegacy prefix. It is therefore possible to include both of these in your application. If you include both, IntentIntegrator will automatically choose the best one.

If you only need to support Android 4.0.3 and newer, you only need the zxing-android-minimal library.

It is also possible to only use the zxing-android-legacy library, but it does not include the latest updates and bugfixes from the ZXing project.

Adding apklib dependency with Maven

Support for Maven apklib is dropped in version 1.2.0.

Use the 1.1.x branch if you need to use this from a Maven project.

Usage

Launch the intent with the default options:

new IntentIntegrator(this).initiateScan(); // `this` is the current Activity

Use from a Fragment:

IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment

// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.

Customize options:

IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setResultDisplayDuration(0);
integrator.setWide();  // Wide scanning rectangle, may work better for 1D barcodes
integrator.setCameraId(0);  // Use a specific camera of the device
integrator.initiateScan();

See IntentIntegrator for more options.

Custom Layout

You can provide a custom layout for the capture activity. Note that you'll need to provide two different layouts if you are using both zxing-android-minimal and zxing-android-legacy.

See sample/src/main/res/layout/custom_capture_layout.xml and sample/src/main/res/layout/custom_capture_layout.xml for examples.

IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureLayout(R.layout.custom_layout);
integrator.setLegacyCaptureLayout(R.layout.custom_legacy_layout);
integrator.initiateScan();

For a cancel/back button, use the ids @id/zxing_back_button for zxing-android-minimal and @id/zxinglegacy_back_button for zxing-android-legacy.

Building locally

./gradlew assemble

To produce .aar artifacts for a Maven repository:

./gradlew uploadArchives

Sponsored by

Journey - Build enterprise mobile apps for iOS and Android. Work in the cloud, code in JavaScript and forget about back-end development.

License

Apache License 2.0

zxing-android-minimal's People

Contributors

andreipro1002 avatar bryancallahan avatar martar avatar rkistner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.