Android Barcode Reader and Qr Code Scanner using Google Mobile Vision

Avaneesh Kumar
Jul 28, 2018 · 3 min read

Google’s Vision API has replaced the ZXING QR Scanner that we were using earlier. Apart from barcode scanning, it serves multiple purposes including face detection.

Advantage over legacy ZXING scanner

Google vision API is faster. It can scan calendars and business cards.
I am attaching a QR code with a calendar event.

Calendar event QrCode

When we scan above QR code with vision API, we get the following:

Besides calendars, we can also scan contacts, driving licenses and more.

I have created a sample of the above mentioned facility.

How to use Barcode Reader Using Google Mobile Vision

Barcode-Reader – Barcode Reader Using Google Mobile Vision

1. Click the above link, download the project and import barcode-reader as module

2. Include the barcode reader dependency in app’s build.gradle

3. You can just launch the scanner activity by calling this method

and get the result into onActivityResult:

4. If you want to make your own activity, implement the activity from BarcodeReader.BarcodeReaderListener and override the necessary methods.

Adding Barcode Reader in Fragment

In fragment the barcode reader can be added easily but the scanner listener barcodeReader.setListener() has to be set manually.

Check the example fragment code in and

Adding Scanner Overlay Scanning Indicator

The overlay animation indicator displays a horizontal line animating from top to bottom. This can be useful in showing cool animations to indicate scanning progress.

To use it, add the com.notbytes.barcode_reader.ScannerOverlay on top of barcode reader fragment using Relative or Frame layout.

        app:use_flash="false" />    <com.notbytes.barcode_reader.ScannerOverlay
        app:square_width="250" /></RelativeLayout>

Additional Options

XML attribute for Barcode Reader

auto_focus – boolean, turn on/off auto focus. Default is true

use_flash – boolean, turn on/off flash. Default is false

XML attribute for Scanner Overlay Indicator

square_width – Width of transparent square

square_height – Height of transparent square

line_color – Horizontal line color

line_speed – Horizontal line animation speed

JAVA Methods

  • Play beep sound

You can play the beep sound when a barcode is scanned. This code is usually called in onScanned() callback.

  • Change beep sound

You can change the default beep sound by passing the file name. Your beep file should be in the project’s assets folder.

  • Pause scanning

The scanning can be paused by calling pauseScanning() method.

  • Resume Scanning

The scanning can be resumed by calling resumeScanning() method.

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do

Você está comentando utilizando sua conta Sair /  Alterar )

Foto do Google

Você está comentando utilizando sua conta Google. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s