Coder Social home page Coder Social logo

alg520 / zxing-android-embedded Goto Github PK

View Code? Open in Web Editor NEW

This project forked from journeyapps/zxing-android-embedded

0.0 1.0 0.0 8.41 MB

Port of the ZXing Android application as an Android library project, for embedding in an Android application.

License: Apache License 2.0

Java 100.00%

zxing-android-embedded's Introduction

ZXing Android Embedded

Barcode scanning library for Android, using ZXing for decoding.

The project is loosely based on the ZXing Android Barcode Scanner application, but is not affiliated with the official ZXing project.

Features:

  1. Can be used via Intents (little code required).
  2. Can be embedded in an Activity, for advanced customization of UI and logic.
  3. Scanning can be performed in landscape or portrait mode.
  4. Camera is managed in a background thread, for fast startup time.

A sample application is available in Releases.

Adding aar dependency with Gradle

From version 3 this is a single library, supporting Gingerbread and later versions of Android (API level 9+). If you need support for earlier Android versions, use version 2.

Add the following to your build.gradle file:

repositories {
    jcenter()
}

dependencies {
    compile 'com.journeyapps:zxing-android-embedded:3.3.0@aar'
    compile 'com.google.zxing:core:3.2.1'
    compile 'com.android.support:appcompat-v7:23.1.0'   // Version 23+ is required
}

android {
    buildToolsVersion '23.0.2' // Older versions may give compile errors
}

Usage with IntentIntegrator

Launch the intent with the default options:

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


// Get the results:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null) {
        if(result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

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.setCameraId(0);  // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();

See IntentIntegrator for more options.

Changing the orientation

To change the orientation, specify the orientation in your AndroidManifest.xml and let the ManifestMerger to update the Activity's definition.

Sample:

<activity
		android:name="com.journeyapps.barcodescanner.CaptureActivity"
		android:screenOrientation="fullSensor"
		tools:replace="screenOrientation" />
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();

Customization and advanced options

See EMBEDDING.

For more advanced options, look at the Sample Application, and browse the source code of the library.

Android Permissions

The camera permission is required for barcode scanning to function. It is automatically included as part of the library. On Android 6 it is requested at runtime when the barcode scanner is first opened.

When using BarcodeView directly (instead of via IntentIntegrator / CaptureActivity), you have to request the permission manually before calling BarcodeView#resume(), otherwise the camera will fail to open.

Building locally

./gradlew assemble

To deploy the artifacts the your local Maven repository:

./gradlew publishToMavenLocal

You can then use your local version by specifying in your build.gradle file:

repositories {
    mavenLocal()
}

Sponsored by

JourneyApps - Creating business solutions with mobile apps. Fast.

License

Apache License 2.0

zxing-android-embedded's People

Contributors

rkistner avatar rehan-vanzyl avatar bugmaker avatar lucasddaniel avatar martar avatar servus7 avatar alberdi avatar bryancallahan avatar commjoen avatar ymenager avatar auchri avatar

Watchers

James Cloos 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.