[Huawei Developers] Freemind R:
Overview

In this article, I will create a demo app along with the integration of Huawei Scan Kit which is based on Cross-platform Technology Xamarin. User can easily scan 1D and 2D barcodes using this application. This Xamarin based application easily detects, magnifies, and recognizes barcodes from a distance. I will provide the easy way of implementing scan kit in Xamarin app.

Service Introduction

Huawei Scan Kit allows reading barcodes in any form like 1D and 2D. It also provides the best scan mechanism to detect, magnifie and recognize the barcodes. it automatically captures the whole barcode even in lowlight, reflective, dirty, blurry, or printed.

Scan Kit supports 13 formats of barcodes such as-

1D barcodes: EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, and ITF

2D barcodes: QR code, Data Matrix, PDF417, and Aztec

Scan Kit provides 4 views of scan barcodes.

1. Default View- Scan barcodes using the camera or from images in the album.

2. Customized View- Scan barcodes using the camera.

3. Bitmap- Scan barcodes using the camera or from images in the album.

4. Multiprocessor- Scan barcodes using the camera or from images in the album.

Recognize multiple barcodes simultaneously.

Work with ML Kit to recognize different objects (such as barcodes and faces) at the same time.

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

App Gallery Integration process

1. Sign In and Add or Choose a project on AppGallery Connect portal

2. Navigate to Project Setting > Add app

3. Add SHA-256 key

4. Navigate to Project settings > download the configuration file

Xamarin Scan Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files from below URL-

https://developer.huawei.com/consum...y-V1/xamarin-sdk-download-0000001057674337-V1

2. Open the XHmsScan-1.2.3.300.sln solution in Visual Studio

3. Navigate to Solution Explorer > Right click on jar > Add >Exsiting Item and choose aar file which downloaded in Step 1

4. Right click on added aar file then choose Properties > Build Action > LibraryProjectZip

Note- Repeat Step 3 & 4 for all aar file

5. Build the Library and make DLL files

6. Success Build

Xamarin App Development

1. Open Visual Studio 2019 and Create a new project

2. Navigate to Solution Explore > Project > Add Folder > Add Json file

3. Navigate to Solution Explore >Project > Add > Add New Folder and keep all DLL files

4. Navigate to Folder(created) > Add > Add Existing and add all DLL files then Select all DLL files and Right Click > Properties >Build Action >None

5. Navigate to Solution Explore > Project > Reference > Right Click > Add References then Navigate to Browse and add all DLL files from recently added Folder

6. Navigate to Solution Explore > Project > Add > Class > Activity

MainActivity.cs

In this activity, I will redirect all the scan view based activity.

using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Android.Content;

namespace Demo
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
private Button btnImage, btnDefault, btnCustom;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.main_view);
btnImage = FindViewById<Button>(Resource.Id.btn_bitmap);
btnImage.Click += delegate
{
Intent intent = new Intent(this, typeof(ImageActivity));
StartActivity(intent);
};

btnDefault = FindViewById<Button>(Resource.Id.btn_bitmap);
btnDefault.Click += delegate
{
Intent intent = new Intent(this, typeof(DefaultActivity));
StartActivity(intent);
};

btnCustom = FindViewById<Button>(Resource.Id.btn_bitmap);
btnCustom.Click += delegate
{
Intent intent = new Intent(this, typeof(DefinedActivity));
StartActivity(intent);
};
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

For more, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203454633259850011