softotalss / BarcodeScanner

Barcode Scanner library for Java, Android with Zxing core
Apache License 2.0
4 stars 2 forks source link
android barcode barcode-scanner datamatrix java qrcode zxing

Barcode Scanner

Barcode Scanner is a library that provides easy integration of Zxing library with your android applications.

Screenshots

Download

You can download an arr from maven releases page.

Or use Gradle:

repositories {
    maven { url 'https://github.com/softotalss/barcodescanner/raw/master/maven-repository' }
}
dependencies {
    implementation 'com.google.zxing:core:x.x.x'
    implementation 'com.github.softotalss:barcodescanner:1.0.2'
}

How do I use Barcode Scanner?

Simple use

public class ScannerActivity extends AppCompatActivity implements BarcodeScannerView.ActivityCallback {

    private ViewGroup mContentFrame;
    private BarcodeScannerView mScannerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        initCamera();
    }

    @Override
    public void onResume() {
        super.onResume();
        startCamera();
    }

    @Override
    public void onPause() {
        stopCamera();
        super.onPause();
    }    

    private void initCamera() {
        mScannerView = new BarcodeScannerView(this);
        mContentFrame.addView(mScannerView);
        // Here setFormats
    }

    private void startCamera() {
        if (mScannerView != null) {
            mScannerView.setResultHandler(this);
            mScannerView.startCamera();
        }
    }

    private void stopCamera() {
        if (mScannerView != null) {
            mScannerView.stopCamera();
        }
    }

    @Override
    public void onResult(Result result) {
        // Get barcode with result.getText()
    } 

    @Override
    public void onErrorExit(Exception e) {
        // An error occurred with the camera, notify to user
    }

Advanced use

// Use flash
void setFlash(boolean flag);
boolean isFlashOn();
public void toggleFlash();
// Read only specific formats
List<BarcodeFormat> formats = new ArrayList<>();
formats.add(BarcodeFormat.QR_CODE);
void setFormats(formats);

BarcodeFormat

Use setFormats only right after initCamera

Simulate landscape

The library read barcodes faster in landscape mode, but in some cases you will need that your app always run in portrait mode. If it's this case, you can use the next config and simulate landscape mode even if your read activity is in portrait mode

void setLandscapeSimulated(boolean landscapeSimulated);

Deployment

  1. update version information
  2. gradlew clean
  3. gradlew :barcodescanner:assembleRelease
  4. gradlew :barcodescanner:publishMavenPublicationToMavenRepository
  5. git add, commit, push (on master branch)

Author

Alejandro Santana - @softotalss on GitHub

This project is based on:

License

Apache 2.0. See the LICENSE file for details.