Skip to content

ZXing (barcode scanner) view for Android

License

Notifications You must be signed in to change notification settings

ferozkhandev/ZXingView

 
 

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 {
    implementation 'com.github.Tetr4:ZXingView:v1.1.0'
}

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();

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

About

ZXing (barcode scanner) view for Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%