English | 中文
This sample code shows how to quickly build barcode scanning functions into your app using the capabilities of the HMS Core Scan Kit. Currently, Scan Kit supports the following barcode formats:
- 1D barcode formats: EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, and ITF-14
- 2D barcode formats: QR Code, Data Matrix, PDF417, and Aztec
Android Studio 3.6.1 or later and JDK 1.8.211 or later.
A Huawei device that runs EMUI 3.0 or later, compatible with HMS Core (APK) 4.0.0 or a generic device running Android 4.4 or later.
Barcode scanning and barcode generating can be achieved in different ways, showcased by the demo.
Default view
The default view mode will start a dedicated Activity
provided by Scan Kit that will display a predefined UI, control the camera and pass back the scanning result via the onActivityResult()
of the original activity (com.example.scankitdemo.MainActivity
in the demo) .
Customized view
In customized view mode, you can define a custom UI, with the help of a com.huawei.hms.hmsscankit.RemoteView
, and then obtain the scanning result through an asynchronous callback. As with the default view mode, you do not need to worry about developing the scanning process or controlling the camera. See com.example.scankitdemo.DefinedActivity
.
Bitmap
Use this mode when you wish to have full control over the input to the scanning process and the moment when you wish to get the results back. In com.example.scankitdemo.CommonActivity
, the demo will pass a Bitmap
to com.huawei.hms.hmsscankit.ScanUtil.decodeWithBitmap()
(definition).
Multi-processor
Recognize multiple barcodes at the same time. When working together with the HMS ML Kit, Scan Kit can detecting both barcodes and human faces. Frame data is transmitted and decoded through the multi-processor API. See com.example.scankitdemo.CommonActivity
and read more about how it works.
Generating barcodes
Generate your own barcodes by calling com.huawei.hms.hmsscankit.ScanUtil.buildBitmap()
(definition) in com.example.scankitdemo.GenerateCodeActivity
.
You can visit the Reddit community to obtain the latest information about HMS Core and communicate with other developers.
If you have any questions about the sample code, try the following:
- Visit Stack Overflow, submit your questions, and tag them with
huawei-mobile-services
. Huawei experts will answer your questions. - Visit the HMS Core section in the HUAWEI Developer Forum and communicate with other developers.
If you encounter any issues when using the sample code, submit your issues or submit a pull request.
The sample code is licensed under Apache License 2.0.