QR code is now an important tool for mobile application traffic entrance as well as function realization, and it is also the traffic entrance of each App. The use scene is getting richer and richer, and it is widely used in mainstream scenes such as payment, travel, catering, life service, smart life, retail and advertising and marketing.
However, in real life, the code-scanning environment such as light intensity, code-scanning angle, distance, etc., camera functions such as zoom, focus, exposure, etc., and the degree of integrity of the code map itself, the degree of curvature, etc. will largely affect the user's experience of code-scanning.
HarmonyOS SDK Harmonization of code-scanning services(Scan Kit), as a system-level code scanning service with hardware and software synergy, helps developers' applications quickly build code map recognition and generation capabilities for various scenarios. The unified code scanning service applies a number of computer vision technologies and AI algorithms, which not only realizes long-distance automatic code scanning, but also optimizes the recognition of a variety of complex code scanning scenarios (e.g., dark light, dirt, blurring, small angle, curved surface code, etc.), and realizes the detection and automatic amplification of long-distance codes or small codes, so as to improve the success rate of code scanning and the user experience.
of which are harmonized sweep servicesDefault interface scanning capabilityProvide system-level experience consistent code scanning interface, including camera preview stream, album code scanning entry, dark environment flash on prompt, support single code and multiple code recognition, with camera pre-authorization, call interface, without the developer to apply for camera privileges again. Suitable for application development in different code scanning scenarios.
Competence Advantage
Simple access: one line of code, simple access; system level interface, package body 0 increase.
Pop-up free: Pre-authorization of system camera privileges to protect user information security.
High recognition rate: apply several CV technologies to improve the success rate and speed of code scanning.
Recognition distance: apply end-side AI algorithm technology to realize long-distance code recognition.
business process
development step
The unified code-sweeping service provides the ability of default interface code-sweeping, and the camera is directly controlled by the code-sweeping interface to realize optimal camera zoom control, adaptive exposure adjustment, adaptive focus adjustment and other operations, which guarantees smooth code-sweeping experience and reduces the workload of developers.
The following example calls Scan Kit's startScanForResult interface to jump to the scanning page.
1. Import the default interface scanning module.scanCoreProvide sweep type definitions thatscanBarcodeProvides methods and parameters for pulling up the default interface sweep, imported as follows.
import { scanCore, scanBarcode } from '@' ;
// Import the logging and error code modules needed for the default interface
import { hilog } from '@'; // import the log module and error code module needed for the default interface.
import { BusinessError } from '@'; // Import the logging and error code modules needed for the default interface.
2. Call the startScanForResult method to pull up the default scanning interface.
Get the result of the sweep by Promise.
[@Entry](/u/4127701)
[@Component](/u/3907912)
struct ScanBarCodePage {
build() {
Column() {
Row() {
Button("Promise with options")
.backgroundColor('#0D9FFB')
.fontSize(20)
.fontColor('#FFFFFF')
.fontWeight()
.align()
.type()
.width('90%')
.height(40)
.margin({ top: 5, bottom: 5 })
.onClick(() => {
// Defining Sweep Parametersoptions
let options: = {
scanTypes: [],
enableMultiMode: true,
enableAlbum: true
};
// callablegetContextinterface to get the current page's associatedUIAbilityContext
(getContext(this), options).then((result: ) => {
// Return after receiving the scanning result
(0x0001, '[Scan CPSample]', `Succeeded in getting ScanResult by promise with options, result is ${(result)}`);
}).catch((error: BusinessError) => {
(0x0001, '[Scan CPSample]',
`Failed to get ScanResult by promise with options. Code:${}, message: ${}`);
});
})
}
.height('100%')
}
.width('100%')
}
}
Get the scanning result through the Callback callback function.
@Entry
@Component
struct ScanBarCodePage {
build() {
Column() {
Row() {
Button('Callback with options')
.backgroundColor('#0D9FFB')
.fontSize(20)
.fontColor('#FFFFFF')
.fontWeight()
.align()
.type()
.width('90%')
.height(40)
.margin({ top: 5, bottom: 5 })
.onClick(() => {
// Defining Sweep Parametersoptions
let options: = {
scanTypes: [],
enableMultiMode: true,
enableAlbum: true
};
// callablegetContextinterface to get the current page's associatedUIAbilityContext
(getContext(this), options,
(error: BusinessError, result: ) => {
if (error) {
(0x0001, '[Scan CPSample]',
`Failed to get ScanResult by callback with options. Code: ${}, message: ${}`);
return;
}
// Return after receiving the scanning result
(0x0001, '[Scan CPSample]', `Succeeded in getting ScanResult by callback with options, result is ${(result)}`);
})
})
}
.height('100%')
}
.width('100%')
}
}
Learn more >>
interviewsUnified Scanning Service Alliance Official Website
gainDefault Interface Scanning Service Development Guidance Document