Skip to content

gehadfatah/zxscannergoda

Repository files navigation

ZXing View for Android

This repository contains code for an Android view that displays the camera's viewfinder and allows scanning barcodes via the ZXing image processing library.

The fragment uses AsyncTasks for smooth scanning, without interrupting the UI-Thread. Changing the display orientation during scanning is also supported.

Download

  1. Add JitPack to your top-level build.gradle:
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
  1. Add the library as a dependency to your apps build.gradle:
dependencies {
    compile 'com.github.Tetr4:ZXingView:master-SNAPSHOT'
}

Usage

  1. Use the ScannerView in you layout:
<de.klimek.scanner.ScannerView
    android:id="@+id/scanner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:reticle_fraction="0.5"
    app:reticle_color="@android:color/holo_green_light"
    app:allow_frontcamera="true"
    app:use_flash="true"
    app:decode_interval="500" />
  1. Add a callback and start/stop the scanner in your activity:
ScannerView scanner = (ScannerView) findViewById(R.id.scanner);
scanner.setOnDecodedCallback(new OnDecodedCallback() {
    @Override
    public void onDecoded(String decodedData) {
        Toast.makeText(MainActivity.this, decodedData, Toast.LENGTH_SHORT).show();
    }
});
scanner.startScanning();
scanner.stopScanning();
  1. Add required permissions and features to AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FLASHLIGHT" />

<uses-feature
    android:name="android.hardware.camera.any"
    android:required="true" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.flash"
    android:required="false" />

Have a look at the sample app for a reference on how to handle runtime permissions for the camera.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages