Interaction of Android Device and HarmonyOS Wearable Device with QR Code Use Case

Mehmet Yozgatlı
Huawei Developers
Published in
4 min readOct 31, 2021

--

Huawei Wear Engine

Introduction

Hello everyone, after a long time, I am with you again with a use case. In this article, I will talk about development for both Android devices and Wearable devices. And I will try to give information from Huawei Wear Engine and Huawei Scan Kit that I used in this development.

Recently, we see frequent use of QR codes on both vaccine cards and country-specific Covid19 cards. That’s why I chose a use case that can bring convenience to people’s lives.

First, I want to start with the development on the Android side. In order to interact with the Android device and the Wearable device, you need to configure the Huawei Wear Engine.

  • What is Wear Engine?

By integrating Wear Engine, your app or service on a phone can send messages and notifications and transfer data to Huawei wearable devices, as well as obtaining the status of the wearable devices. This also works the other way round, which means that an app or service on a Huawei wearable can send messages and transfer data to a phone.

  • What is Scan Kit?

Scan Kit scans, parses, and generates major 1D and 2D barcodes, helping you quickly build barcode scanning functions into your apps.

Implementation

In order to use this service, you need to apply through the Huawei Developer Console. You can use the official document:

You can integrate the SDKs of these two services into your application.

Wear Engine:

Scan Kit:

Android Development

Now we can start coding. On the Android device, we need to have the user select the cards with the QR code I mentioned above. You can get the PDF file from the device using Intent.

We will use Scan Kit to detect the QR code in the PDF file. But since Scan Kit can detect with Image type, you need to first convert the PDF file to Bitmap.

Get QR Code from PDF

Here I used Scan Kit for 2 purposes.

1- Detect QR code from PDF file and display it on Android device.

2- Getting the string value of the QR code detected from the PDF file.

You can send the obtained string from Android device to Wearable device with Wear Engine.

You can check the following documents for the necessary configurations.

  • App-to-App Message Communications :

You can also check the following medium article for configurations.

After performing the steps in this document, you can create a function as follows and send the desired message to the Wearable device connected to the Android device.

Send message to Wearable Device from Android Device

Wearable Development

Now we can talk about development on the Wearable side.

We need to use DevEco Studio IDE for wearable development. You can download the IDE from the link below.

https://developer.harmonyos.com/en/develop/deveco-studio#download

You can also find all the information about the IDE in its official document.

https://developer.harmonyos.com/en/docs/documentation/doc-guides/tools_overview-0000001053582387

We need to convert the string value sent from the Android device to QR code and display it on the watch. To do this, I used the ZXing library that most people use.

You need to add this library to your project as follows.

  • implementation ‘io.openharmony.tpc.thirdlib:BGAQRCode-zxing:1.0.4’

In addition, since we will use the Wear Engine service on the Wearable Device side, we need to add it to our project. You can check the document below.

  • App-to-App Message Communications :

Now it’s time to capture the messages from the Android device on the Wearable device.

Register Receiver

You can write a function like below to convert the message to QR Code after you get the message with Wear Engine Receiver.

Create and Display QR Code

In the function, I also set the QR Code to the Image component. Thus, I mentioned all the development steps required for the QR Code use case.

Output

Output 1
Output 2

Conclusion

A useful application can be developed using Wear Engine and Scan Kit. You can also add more different features according to your own application.
I hope it will be a useful article.

References

Github Repo:

--

--