目录

scanCore (Common Barcode Scanning Information)

Module Overview

The scanCore module is the common data type module of Scan Kit. It provides common data type definitions such as barcode type enumeration, error codes, and canning source of the default scanning UI. This module does not directly provide the barcode scanning capability. Instead, it provides basic data type support for the scanBarcode (scanning barcodes using the default UI), customScan (scanning barcodes using a custom UI), detectBarcode (image recognition), and generateBarcode (barcode image generation) functional modules. It also provides the isDefaultScanSupported and isCustomScanSupported APIs to check whether the current device supports the corresponding capabilities before calling the barcode scanning function.

Since: 4.0.0(10)

Modules to Import

import { scanCore } from '@kit.ScanKit';

ScanType

Enumerates code types.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 4.1.0(11).

System capability: SystemCapability.Multimedia.Scan.Core

Since: 4.0.0(10)

Name Value Description
FORMAT_UNKNOWN 0 Unknown type. This parameter is used for scenarios where the type of code to be scanned is unknown beforehand. It cannot be used for barcode image generation.
AZTEC_CODE 1 Aztec barcode type.
CODABAR_CODE 2 Codabar barcode type.
CODE39_CODE 3 Code 39 barcode type.
CODE93_CODE 4 Code 93 barcode type.
CODE128_CODE 5 Code 128 barcode type.
DATAMATRIX_CODE 6 Data Matrix barcode type.
EAN8_CODE 7 EAN-8 type.
EAN13_CODE 8 EAN-13 type.
ITF14_CODE 9 ITF-14 type.
PDF417_CODE 10 PDF417 type.
QR_CODE 11 QR Code type.
UPC_A_CODE 12 UPC-A type.
UPC_E_CODE 13 UPC-E type.
MULTIFUNCTIONAL_CODE 14 Multifunctional code type. The barcode image generation capability does not support this type currently.
ONE_D_CODE 100 Barcode set type, including Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF-14, UPC-A, and UPC-E. This parameter cannot be used for barcode image generation.
TWO_D_CODE 101 2D code set type, including Aztec, Data Matrix, PDF417, QR Code, and MULTIFUNCTIONAL CODE. This parameter cannot be used for barcode image generation.
ALL 1001 All the preceding types. This parameter cannot be used to generate barcode images.

ScanErrorCode

Enumerates scanning error codes.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.Scan.Core

Since: 4.1.0(11)

Name Value Description
INTERNAL_ERROR 1000500001

Internal error. For details, please refer to 1000500001 Internal Error.

Atomic service API: This API can be used in atomic services since API version 4.1.0(11).

SCAN_SERVICE_CANCELED 1000500002

The user cancels the scanning. For details, please refer to 1000500002 Scanning Canceled by User.

Atomic service API: This API can be used in atomic services since API version 5.0.0(12).

Since: 5.0.0(12)

ScanSource

Enumerates scanning result sources. It specifies whether the default source is the camera preview stream or an image in the album.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 6.0.2(22).

System capability: SystemCapability.Multimedia.Scan.Core

Since: 6.0.2(22)

Name Value Description
CAMERA 0 The default source of the scanning result is the camera preview stream.
PHOTO 1 The default source of the scanning result is an image in the album.

isDefaultScanSupported

isDefaultScanSupported(): boolean

Checks whether the current device supports scanning on the default UI.

Model restriction: This API can be used only in the stage model.

Atomic service API: This API can be used in atomic services since API version 26.0.0.

System capability: SystemCapability.Multimedia.Scan.Core

Since: 26.0.0

Returns:

Type Description
boolean Query result, indicating whether scanning using the default UI is supported. The options are true (yes) and false (no).

Example:

import { scanCore } from '@kit.ScanKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let isSupported: boolean = scanCore.isDefaultScanSupported();
if (isSupported) {
  hilog.info(0x0001, '[Scan Sample]', 'Default scan is supported on this device.');
  // The current device supports barcode scanning on the default UI. You can start the barcode scanning page or perform the next step.
  // ...
} else {
  // The current device does not support barcode scanning on the default UI.
  hilog.info(0x0001, '[Scan Sample]', 'Default scan is not supported on this device.');
}

isCustomScanSupported

isCustomScanSupported(): boolean

Checks whether the current device supports scanning on a custom UI.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.Scan.Core

Since: 26.0.0

Returns:

Type Description
boolean Query result, indicating whether scanning using a custom UI is supported. The options are true (yes) and false (no).

Example:

import { scanCore } from '@kit.ScanKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let isSupported: boolean = scanCore.isCustomScanSupported();
if (isSupported) {
  hilog.info(0x0001, '[Scan Sample]', 'Custom scan is supported on this device.');
  // The current device supports barcode scanning on a custom UI. You can start the barcode scanning page or perform the next step.
  // ...
} else {
  // The current device does not support barcode scanning on a custom UI.
  hilog.info(0x0001, '[Scan Sample]', 'Custom scan is not supported on this device.');
}