Convert Figma logo to code with AI

dlazaro66 logoQRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes

1,901
491
1,901
54

Top Related Projects

Barcode Scanner Libraries for Android

Barcode scanner library for Android, based on the ZXing decoder

Code scanner library for Android, based on ZXing

32,747

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

1,488

a simple QRCode generation api for java built on top ZXING

Quick Overview

QRCodeReaderView is an Android library that provides a simple and customizable QR code scanning interface. It utilizes the ZXing library for QR code decoding and offers a straightforward way to integrate QR code scanning functionality into Android applications.

Pros

  • Easy integration with minimal setup required
  • Customizable UI elements for the scanning interface
  • Supports continuous scanning without the need for button presses
  • Provides callbacks for successful scans and errors

Cons

  • Limited to QR codes only, not supporting other barcode formats
  • Depends on the ZXing library, which may increase app size
  • Documentation could be more comprehensive
  • Not actively maintained (last update was in 2018)

Code Examples

  1. Basic QR code scanning setup:
class MainActivity : AppCompatActivity(), QRCodeReaderView.OnQRCodeReadListener {
    private lateinit var qrCodeReaderView: QRCodeReaderView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        qrCodeReaderView = findViewById(R.id.qrdecoderview)
        qrCodeReaderView.setOnQRCodeReadListener(this)
        qrCodeReaderView.setQRDecodingEnabled(true)
        qrCodeReaderView.setAutofocusInterval(2000L)
        qrCodeReaderView.setBackCamera()
    }

    override fun onQRCodeRead(text: String?, points: Array<PointF>?) {
        // Handle the scanned QR code result
    }
}
  1. Customizing the QR code scanning interface:
// Add a custom overlay to the QR code scanner
val myCustomView = LayoutInflater.from(this).inflate(R.layout.custom_overlay, null)
qrCodeReaderView.addView(myCustomView)

// Set a custom square for highlighting the QR code
val pointsOverlayView = PointsOverlayView(this)
qrCodeReaderView.setPointsOverlayView(pointsOverlayView)
  1. Handling lifecycle events:
override fun onResume() {
    super.onResume()
    qrCodeReaderView.startCamera()
}

override fun onPause() {
    super.onPause()
    qrCodeReaderView.stopCamera()
}

Getting Started

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3'
}
  1. Add the QRCodeReaderView to your layout:
<com.dlazaro66.qrcodereaderview.QRCodeReaderView
    android:id="@+id/qrdecoderview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. Initialize and configure the QRCodeReaderView in your activity:
class MainActivity : AppCompatActivity(), QRCodeReaderView.OnQRCodeReadListener {
    private lateinit var qrCodeReaderView: QRCodeReaderView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        qrCodeReaderView = findViewById(R.id.qrdecoderview)
        qrCodeReaderView.setOnQRCodeReadListener(this)
        qrCodeReaderView.setQRDecodingEnabled(true)
        qrCodeReaderView.setAutofocusInterval(2000L)
        qrCodeReaderView.setBackCamera()
    }

    override fun onQRCodeRead(text: String?, points: Array<PointF>?) {
        // Handle the scanned QR code result
    }
}

Competitor Comparisons

Barcode Scanner Libraries for Android

Pros of barcodescanner

  • Supports multiple barcode formats, not just QR codes
  • More actively maintained with recent updates
  • Includes a sample app for easy testing and implementation

Cons of barcodescanner

  • Larger library size due to support for multiple formats
  • May have a steeper learning curve for basic QR code scanning

Code Comparison

QRCodeReaderView:

qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
qrCodeReaderView.setQRDecodingEnabled(true);
qrCodeReaderView.setAutofocusInterval(2000L);
qrCodeReaderView.startCamera();

barcodescanner:

BarcodeView barcodeView = (BarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.decodeSingle(new BarcodeCallback() {
    @Override
    public void barcodeResult(BarcodeResult result) {
        // Handle the result
    }
});

Both libraries offer easy-to-use APIs for scanning QR codes, but barcodescanner provides more flexibility with multiple barcode format support. QRCodeReaderView focuses solely on QR codes, which may be preferable for simpler use cases. The code snippets show that both libraries require minimal setup, with barcodescanner offering a callback-based approach for handling results.

Barcode scanner library for Android, based on the ZXing decoder

Pros of zxing-android-embedded

  • More comprehensive barcode scanning capabilities, supporting multiple formats beyond QR codes
  • Better maintained with more frequent updates and a larger community
  • Offers a more flexible API for customization and integration

Cons of zxing-android-embedded

  • Larger library size, which may impact app size
  • Steeper learning curve due to more complex API
  • May require more setup and configuration compared to QRCodeReaderView

Code Comparison

QRCodeReaderView:

qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
qrCodeReaderView.setQRDecodingEnabled(true);
qrCodeReaderView.startCamera();

zxing-android-embedded:

IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan a QR Code");
integrator.setCameraId(0);
integrator.initiateScan();

Both libraries offer easy-to-use APIs for QR code scanning, but zxing-android-embedded provides more options for customization and supports additional barcode formats. QRCodeReaderView focuses specifically on QR codes and offers a simpler implementation for basic use cases. The choice between the two depends on the project's requirements, with zxing-android-embedded being more suitable for complex scanning needs and QRCodeReaderView for straightforward QR code scanning functionality.

Code scanner library for Android, based on ZXing

Pros of code-scanner

  • More active development with recent updates and bug fixes
  • Supports a wider range of barcode formats, including QR codes, Data Matrix, and more
  • Offers customizable UI elements and camera controls

Cons of code-scanner

  • Larger library size, which may impact app size
  • Steeper learning curve due to more features and configuration options

Code Comparison

QRCodeReaderView:

qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
qrCodeReaderView.setQRDecodingEnabled(true);
qrCodeReaderView.setAutofocusInterval(2000L);

code-scanner:

codeScanner = CodeScanner(this, scannerView)
codeScanner.camera = CodeScanner.CAMERA_BACK
codeScanner.formats = CodeScanner.ALL_FORMATS
codeScanner.autoFocusMode = AutoFocusMode.SAFE
codeScanner.scanMode = ScanMode.SINGLE

Summary

code-scanner offers more features and flexibility compared to QRCodeReaderView, including support for multiple barcode formats and customizable UI elements. However, this comes at the cost of a larger library size and potentially more complex implementation. QRCodeReaderView is simpler and more focused on QR code scanning, which may be preferable for projects with specific QR code requirements. The choice between the two libraries depends on the project's needs, such as required barcode formats, desired customization options, and development complexity preferences.

32,747

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Pros of zxing

  • More comprehensive barcode support, including multiple formats beyond QR codes
  • Larger community and longer development history, leading to better stability and documentation
  • Supports multiple platforms (Android, Java SE, iOS) beyond just Android

Cons of zxing

  • Larger library size, which may impact app size and performance
  • More complex integration process compared to QRCodeReaderView's simpler implementation
  • May require more configuration and customization for basic QR code scanning tasks

Code Comparison

QRCodeReaderView:

qrCodeReaderView.setOnQRCodeReadListener(new QRCodeReaderView.OnQRCodeReadListener() {
    @Override
    public void onQRCodeRead(String text, PointF[] points) {
        // Handle QR code result
    }
});

zxing:

IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan a QR Code");
integrator.initiateScan();

The code comparison shows that QRCodeReaderView offers a more straightforward implementation for QR code scanning, while zxing requires additional setup but provides more flexibility for various barcode formats.

1,488

a simple QRCode generation api for java built on top ZXING

Pros of QRGen

  • Supports generating QR codes, while QRCodeReaderView is focused on reading
  • Offers more customization options for QR code generation
  • Provides support for multiple output formats (image, SVG, etc.)

Cons of QRGen

  • Lacks QR code scanning functionality
  • May have a steeper learning curve due to more configuration options
  • Less focused on Android-specific implementation compared to QRCodeReaderView

Code Comparison

QRGen (Generating a QR code):

QRCode qrCode = QRCode.from("Hello, World!")
                      .withSize(250, 250)
                      .withCharset("UTF-8");
BufferedImage qrImage = qrCode.to(ImageType.PNG).bufferedImage();

QRCodeReaderView (Setting up QR code scanning):

qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
qrCodeReaderView.setQRDecodingEnabled(true);
qrCodeReaderView.setAutofocusInterval(2000L);

These code snippets highlight the different focus areas of the two libraries. QRGen is centered around generating QR codes with various options, while QRCodeReaderView is designed for efficiently scanning and decoding QR codes on Android devices.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

QRCodeReaderView Download Android Arsenal Build Status

Disclaimer: This project is no longer actively maintained

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes.

This project implements an Android view which show camera and notify when there's a QR code inside the preview.

Some Classes of camera controls and autofocus are taken and slightly modified from Barcode Scanner Android App.

You can also use this for Augmented Reality purposes, as you get QR control points coordinates when decoding.

Usage

  • Add a "QRCodeReaderView" in the layout editor like you actually do with a button for example.
  • In your onCreate method, you can find the view as usual, using findViewById() function.
  • Create an Activity which implements onQRCodeReadListener, and let implements required methods or set a onQRCodeReadListener to the QRCodeReaderView object
  • Make sure you have camera permissions in order to use the library. (https://developer.android.com/training/permissions/requesting.html)

 <com.dlazaro66.qrcodereaderview.QRCodeReaderView
        android:id="@+id/qrdecoderview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

  • Start & Stop camera preview in onPause() and onResume() overriden methods.
  • You can place widgets or views over QRDecoderView.
public class DecoderActivity extends Activity implements OnQRCodeReadListener {

    private TextView resultTextView;
	private QRCodeReaderView qrCodeReaderView;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_decoder);
        
        qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
        qrCodeReaderView.setOnQRCodeReadListener(this);

    	  // Use this function to enable/disable decoding
        qrCodeReaderView.setQRDecodingEnabled(true);

        // Use this function to change the autofocus interval (default is 5 secs)
        qrCodeReaderView.setAutofocusInterval(2000L);

        // Use this function to enable/disable Torch
        qrCodeReaderView.setTorchEnabled(true);

        // Use this function to set front camera preview
        qrCodeReaderView.setFrontCamera();

        // Use this function to set back camera preview
        qrCodeReaderView.setBackCamera();
    }

    // Called when a QR is decoded
    // "text" : the text encoded in QR
    // "points" : points where QR control points are placed in View
	@Override
	public void onQRCodeRead(String text, PointF[] points) {
		resultTextView.setText(text);
	}
    
	@Override
	protected void onResume() {
		super.onResume();
		qrCodeReaderView.startCamera();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		qrCodeReaderView.stopCamera();
	}
}

Add it to your project

Add QRCodeReaderView dependency to your build.gradle


dependencies{
      compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3'
}

Note: There is an issue with gradle 2.10, if you declare your dependency and it can't be found in jCenter repository (could not find qrcodereaderview.jar Searched in the following locations: or similar), try to declare the library dependency like this:


dependencies{
      compile ('com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3@aar'){
        transitive = true
      }
}

And in some cases, you need to clean your Gradle cache ./gradlew build --refresh-dependencies

Do you want to contribute?

Please send a PR or open an issue with your comments. See CONTRIBUTING file for further information

Libraries used in this project

Screenshots

Image

Developed By

  • David Lázaro Esparcia
Follow me on Twitter Add me to Linkedin

Who's using it

Does your app use QRCodeReaderView? If you want to be featured on this list drop me a line.

License

Copyright 2017 David Lázaro

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.