Build Powerful Code Scanning Capabilities Using HMS Scan Kit

Merve Nur TÜRK
4 min readNov 3, 2020

--

Photo by Albert Hu on Unsplash

Hello to every coders. Today we will talk about HMS Scan Kit which is an in-app scanner and generator for 1D and 2D barcodes connects your app. You can build powerful capabilities such as auto zoom for small or distant barcodes and enhanced recognition in complex scenarios.

Scan Kit can be integrated into both Android and iOS systems. You will find android code samples in this article.

Capabalities

13 mainstream formats
Supports QR Code, Data Matrix, PDF417, Aztec, EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, and ITF.

Enhanced recognition
Detects barcodes despite low visibility, glare, damage, distortion, or blur.

Auto zoom
Zooms in to small or distant barcodes.

Multi-code detection
Processes up to 5 barcodes simultaneously.

Structured data extraction
Lets your app quickly identify usage scenarios such as connecting to Wi-Fi or adding a calendar event.

QR code generation
Converts your input to the best version and error correction level.

Advantages

  • Uses multiple CV technologies to improve the scanning success rate and speed.
  • Allows you to directly call the preset scanning screen or customize the UI and process based on open APIs.
  • Supports mainstream code systems around the world. More code systems and scenarios will be supported later.

Building Scaning Capabalities

Scan Kit can be called in four ways, from which you can choose as needed.

Let’s code :)

Before using HMS kits, we have to make sure we connect our project to AppGallery. You can find detailed information on how to integrate AppGallery Connect SDK into the project via the link.

Implement needed dependancy app-level build.gradle file:

Default View:

In Default View mode, Scan Kit scans barcodes using the camera or from images in the album, and also provides activities that can be directly used. You do not need to worry about designing a UI as Scan Kit provides one.

  • Create options which are you want to scan:
  • Start the scan:
  • Get the data from barcode and show it:

Customized View:

In Customized View mode, you do not need to worry about developing the scanning process or camera control. Scan Kit will do all these tasks for you. However, you will need to design the scanning UI.

  • Set layout resource of activity:
  • Set the scanning area. Set the parameters as required:
  • Set the width and height of the barcode scanning box to 300 dp:
  • Initialize the remote view and set the barcode type. You can use also ALL_SCAN_TYPE for all barcode formats:
  • Load the customized view to the activity:
  • Subscribe to the recognition result callback event:
  • Set a lifecycle listener for the remote view:

Bitmap: Scanning Barcodes Using the Camera

The service process of scans barcodes uses the camera in Bitmap mode.

  • Firstly request permission from user to use camera:
  • Open camera using openCamera() method:
  • Get the scanning result from onActivityResult() override method:
  • Show scanning result on screen:

Bitmap: Scanning Barcodes from Images

The service process of scans barcodes from images in Bitmap mode.

  • Firstly request permission from user to use external starage:
  • Call the system album:
  • Create analyzer options and pass the bitmap data. Get the result:
  • Show the result:

By making these practises, you will learn HMS Scan Kit and you can produce a good project according to your project requirements. Hope this article to useful. Stay with coding :)

--

--