• Stars
    star
    293
  • Rank 141,748 (Top 3 %)
  • Language
    Java
  • License
    BSD 3-Clause "New...
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android barcode reader using google vision library

Barcode Reader - Google Mobile Vision

Android Barcode Reader library using Google Mobile Vision. This library is built on top of google mobile vision sample adding improvements and fixing few bugs.

Download Example

Demo

How to Use

  1. Include the barcode reader dependency in app's build.gradle
dependencies {
    // google mobile vision
    implementation 'com.google.android.gms:play-services-vision:11.0.2'

    // barcode reader
    implementation 'info.androidhive:barcode-reader:1.1.5'
}
  1. Add the barcode reader fragment to your activity
<fragment
        android:id="@+id/barcode_fragment"
        android:name="info.androidhive.barcode.BarcodeReader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:auto_focus="true"
        app:use_flash="false" />
  1. Implement your activity from BarcodeReader.BarcodeReaderListener and override the necessary methods.
public class MainActivity extends AppCompatActivity implements BarcodeReader.BarcodeReaderListener {

    private BarcodeReader barcodeReader;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        barcodeReader = (BarcodeReader) getSupportFragmentManager().findFragmentById(R.id.barcode_fragment);
    }


    @Override
    public void onScanned(Barcode barcode) {
        // play beep sound
        barcodeReader.playBeep();
    }

    @Override
    public void onScannedMultiple(List<Barcode> list) {

    }

    @Override
    public void onBitmapScanned(SparseArray<Barcode> sparseArray) {

    }

    @Override
    public void onScanError(String s) {

    }
    
    @Override
    public void onCameraPermissionDenied() {
            Toast.makeText(getApplicationContext(), "Camera permission denied!", Toast.LENGTH_LONG).show();
    }
}

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 BarcodeFragment.java and BarcodeFragmentTestActivity.java

https://github.com/ravi8x/Barcode-Reader/tree/master/example/src/main/java/info/androidhive/barcodereader

Adding Scanner Overlay Scanning Indicator

The overlay animation indicator displays a horizontal line animating from top to bottom. This will be useful to to show some cool animation to indicate scanning progress.

To use it, add the info.androidhive.barcode.ScannerOverlay on top of barcode reader fragment using Relative or Frame layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout ...>

    <fragment
        android:id="@+id/barcode_fragment"
        android:name="info.androidhive.barcode.BarcodeReader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:auto_focus="true"
        app:use_flash="false" />

    <info.androidhive.barcode.ScannerOverlay
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#44000000"
        app:line_color="#7323DC"
        app:line_speed="6"
        app:line_width="4"
        app:square_height="200"
        app:square_width="200"/>

</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 the barcode is scanned. This code is usually called in onScanned() callback.

@Override
    public void onScanned(final Barcode barcode) {
        Log.e(TAG, "onScanned: " + barcode.displayValue);
        barcodeReader.playBeep();
        });
    }
  • Change beep sound

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

barcodeReader.setBeepSoundFile("shutter.mp3");
  • Pause scanning

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

barcodeReader.pauseScanning();
  • Resume Scanning

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

barcodeReader.resumeScanning();

Know Issues

  • Camera stream is not smooth. It's because of camera resolution.
  • Sometimes screen turns black after Camera permission is granted.

More Repositories

1

AndroidSQLite

Android SQLite example with CRUD Operations. Simple Notes app is created in this project.
Java
156
star
2

RxAndroidExamples

RxJava and RxAndroid complete beginner examples
Java
126
star
3

Android-Image-Picker-and-Cropping

Android choosing image from camera or gallery with Crop functionality
Java
115
star
4

Android-Font-Awesome

Android library to use the Font Awesome icons in android apps
Java
101
star
5

Android-E-Commerce-PayTM

Android e-commerce with PayTM payment gateway integration
Java
94
star
6

Android-DataBindng-RecyclerView

Android RecyclerView DataBinding example. A simple profile screen is demonstrated.
Java
78
star
7

ViewPager2-Examples

Android ViewPager2 examples
Java
77
star
8

AndroidMaterialTabs

Implementing android Tabs using support library.
Java
57
star
9

AndroidLocation

Android location updates using FusedLocationApi
Java
55
star
10

RxJavaRetrofitNotesApp

RxJava retrofit networking library with an example of Notes App
Java
50
star
11

Laravel-PayTM-Server

PayTM backend for e-commerce app
PHP
49
star
12

RoomDatabase

Android Architecture Component - Room Persistency Library example
Java
46
star
13

AndroidCamera

Android camera example using Camera 1 API
Java
36
star
14

RxJavaFlightTicket

RxJava android example demonstrating FlatMap and ConcatMap operators
Java
26
star
15

android-in-app-review-api

Android example of using Google In-App review API to rate app
Java
25
star
16

RxJavaInstantSearch

Java
24
star
17

PagingLocal

Android Architecture Component - Paging room database with local data
Java
21
star
18

LiveData

Android Architecture Component - LiveData example
Java
19
star
19

FacebookShimmer

Android adding loader screen using Facebook Shimmer library.
Java
18
star
20

ViewModel

Android Architecture Component - ViewModel example
Java
18
star
21

Android-Timber

Android Timber logging tool example
Java
10
star
22

GradientView

Android gradient background view library
Java
6
star
23

Annotations-Test

Java
2
star