Introduction
Today, you are going to learn about the Google Vision API using Android Studio and we are going to build a barcode reader app to scan the barcodes. Please follow the below steps carefully to build the Barcode Reader App.
Google API
- Google Vision API is used to find the objects like images, faces in photos, and videos, and barcodes.
- It recognizes the texts and other things which are digitally captured; thus, it is very useful to build our barcode reader app.
Barcode API Overview
- This app will let us to detect the information from a barcode with the help of Vision API.
- A barcode is classified into 1d Barcode and 2d Barcode.
- To know more about it, you can visit the Barcode API information page from Google Developers portal.
Requirements
- Android Studio
- How to code
- Understanding basic functionlaities of how API works
- Free to learn
Steps to follow
Add the below code in "build gradle" to add library files to our Barcode reader.
- compile 'com.google.android.gms:play-services-vision:11.0.2'
Now, we are going to include Barcode Reader library to work correctly. First, we need to build the gradle codes and Android Hive. Then, add Barcode Reader code to it.
- build.gradle
- dependencies {
-
- implementation 'info.androidhive:barcode-reader:1.1.5'
- implementation 'com.google.android.gms:play-services-vision:11.0.2'
- }
It is time to add Activity fragment to which we can invoke the Camera fragment.
- <fragment
- android:id="@+id/barcode_scanner"
- android:name="info.androidhive.barcode.BarcodeReader"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:auto_focus="true"
- app:use_flash="false" />
- This is code for Camera Actvity
Now, let's add the following code to work our project correctly and name it as BarcodeReader.BarcodeReader.java in class library.