Git Product home page Git Product logo

android-lib-zxingcaptureactivity's Introduction

android-lib-ZXingCaptureActivity

This library provides an activity which has the feature of barcode reader, based on ZXing core library. This project contains files derived from ZXing project.

Maven Central

Usage

This library is published to Maven Central. You can use android-libZXingCaptureActivity by writing dependencies on your build.gradle as below.

repositories {
    mavenCentral()
}
dependencies {
    compile 'info.vividcode.android.zxing:capture-activity:2.3.0-1.+'
}

An activity which this library provides is info.vividcode.android.zxing.CaptureActivity. To use it, you need to declares it. (You can also define subclass of CaptureActivity and use it, if you want.)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.example.your.app.pkg">
    <application>
        <activity android:name="info.vividcode.android.zxing.CaptureActivity"
            android:theme="@style/Theme.ZXingCaptureActivity"
            android:screenOrientation="landscape"/>

To start CaptureActivity activity and receive result of barcode scanning, call startActivityForResult method as below.

  // Create intent.
  Intent captureIntent = new Intent(this, CaptureActivity.class);
  // Using `CaptureActivityIntents`, set parameters to an intent.
  // (There is no requisite parameter to set to an intent.)
  // For instance, `setPromptMessage` method set prompt message displayed on `CaptureActivity`.
  CaptureActivityIntents.setPromptMessage(captureIntent, "Barcode scanning...");
  // Start activity.
  startActivityForResult(captureIntent, 1);

After reading barcode, you receive the result through onActivityResult callback method.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == 1) {
    if(resultCode == RESULT_OK) {
      CaptureResult res = CaptureResult.parseResultIntent(data);
      Toast.makeText(this, res.getContents() + " (" + res.getFormatName() + ")", Toast.LENGTH_LONG).show();
    } else {
      // Process comes here when “back” button was clicked for instance.
    }
  }
}

License

This project is released under the Apache License, Version 2.0.

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.