How to Generate QRCode in HOS Devices — Create your own AntiCovid QRCode

ZhangAnmy
Huawei Developers
Published in
2 min readDec 24, 2021

Introduction: QRCode is very common in our life, such as AntiCovid code. How to generate QRCode in HOS devices, I’ll introduce the detail in the article. Crate a special AntiCovid QRCode in your HOS smart watch, then you can display the QRCode in your watch without having to take out your phone. Isn’t it cool? Let’s start.

1. The democode from Huawei codelabs can work in Mobile HOS without zxing library.

Please check the detail in “Codelabs: QRCodeDemo”

2. To generate QRCode in HOS smart watch

1)Based on the democode from Huawei Codelabs, import zxing library in build.gradle
Add the following dependency to the build.gradle file of the module and sync the project

implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zbar:1.0.5'
implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-zxing:1.0.4'
implementation 'io.openharmony.tpc.thirdlib:BGAQRCode-core:1.0.4'

2)Use below code to generate QRCode in smartwatch project

PixelMap pixelMap = QRCodeEncoder.syncEncodeQRCode(CONTENT, SIZE, SIZE);
mImage.setPixelMap(pixelMap);

3)Below is the demo code which integrated jinrishici api (https://v2.jinrishici.com/) and Huawei wearengine(https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/service-introduction-0000000000018585). When open the watch app, it will show a sentence of poem and watch app can receive the message from mobile and create a new QRCode. The detail code please check the github.

Please check the mobile side code that mobile communicate with watch using wearengine: https://github.com/huaweicodelabs/WearEngine.

Conclusion

This article shows the details for creating QRCode in HOS smart watch. And it shows how to connect mobile and watch with wearengine. You can also integrate some APIs in your watch app to make it looks better.

Reference

  1. https://github.com/huaweicodelabs/harmonyos-codelabs
  2. Generating a Signing Certificate Fingerprint
  3. https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/service-introduction-0000000000018585

Merry Christmas and Happy New Year ~~

--

--