SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

Time:2022-5-24

sap. ndc. Barcodescannerbutton: button control used to start the barcode scanning process (display barcode icon). If the local scanning function is not available or the camera function is not granted, the button is either hidden or provides backup by opening a dialog box with input fields, in which the barcode can be entered manually. After codescanner is loaded, it is executedinitmethod:

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

    //    * Feature vector (sap.Settings.isFeatureEnabled) is available
    //  * Barcode scanner is enabled by the Feature Vector
    //  * Barcode scanner Cordova plug-in (cordova.plugins.barcodeScanner) or zxing-js (ZXing.BrowserMultiFormatReader) is available

The available attribute defaults to true:
SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

native device capabilities should be by default enabled if there is no feature vector available to restrict the capability.

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

Cordova API not detected in browser:
SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

Then try to getZXingAPIThis is an asynchronous process.

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

oZXingScannerAPIAvailable.
SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

After clicking the barcode button, execute the code in line 129 belowscanmethod.

If the barcode scanning function is not available, start the barcode scanning process, display the real-time input from the camera or display the dialog box to enter the value directly.

Barcode scanning is done asynchronously. When it is triggered, the function returns without waiting for the scan process to complete. The application must provide callback functions to respond to successful scans, errors during scans, and real-time input events on dialog boxes.

Fnsuccess passes an object with text, formatting, and cancellation properties. Text is the text representation of barcode data, format is the detected barcode type, and cancel is whether the user cancels scanning. Fnerror gives the error, and fnliveupdate is passed the new value entered in the input field of the dialog box.

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

Only when cordovascanner API is available, the following branch of line 584 is entered:

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

Otherwise, enter line 618 and a dialog box will pop up.

SAP ui5 barcodescanerbutton feature detection, Cordova API detection and other logic

SAP Fiori client is the native mobile application runtime container of SAP Fiori application. SAP Fiori client allows users to access their SAP Fiori applications online. Later, I will introduce how to solve the problem of unavailable Cordova plug-in in Fiori client.