# QR Code Scan
QR code scan.
# Manifest Declaration
You need to declare the use of this API in the manifest's features member:
{"name": "system.barcode"}
# Module Import
Before using this service in a component, you need to import the module in the script section of the UX document.
import barcode from '@system.barcode'
Or
let barcode = require("@system.barcode")
# Methods
This service has the following methods:
# scan({success,fail,cancel,complete})
This method scans a QR code using the camera of the device.
# Arguments
This method requires an object with the following attributes:
success(function(res)). Optional callback function corresponding to the successful execution.res.resultis astringwith the parsed content.
fail(function(res, code)). Optional callback function corresponding to the failed execution.codeis201when the user rejects the request for permission to use the camera.
cancel(function()). Optional callback function corresponding to an execution canceled by the user.complete(function()). Optional callback function corresponding to the end of the execution.
Example:
barcode.scan({
success:function(data){
console.log("handling success: " + data.result);
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
})