OoAmosoO / android-lib-ZXingCaptureActivity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

License:Apache License 2.0


Languages

Language:Java 100.0%