Simphony JavaScript Extensibility

Device specific

Android camera to scan barcodes/QR codes

Overview

The Simphony Android POS client has the capability to read barcodes and QR codes from Android device’s camera using the third party library Google MLkit.

The key functions of the Android Barcode scanner feature are:

  • The Android POS application opens the camera with a button click.
  • SimphonyExtensibilityAPI is used to subscribe to Barcode events
  • When a barcode or QR code is scanned, the POS sends the Extensibility Barcode event to all subscribed JavaScript Extensibility scripts.
  • The JavaScript Extensibility scripts examine the Barcode data. They might display or use the data, the format and the type of Barcode or QR code on Ops.

Subscribing to Barcode Scanner Events

JavaScript Extensibility scripts use the standard model for subscribing to POS events. JavaScript Extensibility scripts use the standard model for subscribing to POS events.

var _api = SimphonyExtensibilityAPI;
_api.Eventing.SubscribeToEvent('OpsBarcodePreviewEvent', OnOpsBarCodeEvent);

Consuming Barcode Scanner Events

The Barcode Scanner event follows the standard SIM event method signature. The args are of type OpsBarcodePreviewEventArgs.

function OnOpsBarCodeEvent(sender, args)
{
    if (!args.Handled)
    {
        args.Handled = true;
        
        if (args.BarcodeString != null)
        {
            showMessage('Barcode' + args.BarcodeType +',' + args.BarcodeFormat + ',' + args.BarcodeString + ',' + args.RawBarcodeString );
        }
        else
        {
            showMessage('No Barcode scanned!');
        }
    }

    return _api.Eventing.Continue;
}

All JavaScript Extensibility scripts that subscribe to this event are executed. It is critical to validate that no other JavaScript Extensibility script has consumed this data. It is also important for JavaScript Extensibility scripts to set Handled to true, so that Barcode events are not processed twice. This should only be done if the JavaScript Extensibility event consumes the Barcode scanner data.

Notes on OpsBarcodePreviewEventArgs:

Property Description
ManuallyEntered Set if the barcode is keyed in rather than scanned, using an Ops command.
BarcodeType Get the barcode or QR code type.
BarcodeFormat Get the barcode or QR code format.
BarcodeString Get the barcode or QR code string data.
RawBarcodeString Sometimes the barcode or QR code string data is set as rawdata.
Handled Set to true when a JavaScript Extensibility script consumes this Barcode.

Limitations

This feature is only available for Android devices with camera.

Sample JavaScript Extensibility Script

var _api = SimphonyExtensibilityAPI;
_api.Eventing.SubscribeToEvent('OpsBarcodePreviewEvent', OnOpsBarCodeEvent);

//The button should be configured as Function | Sim Inquire. The button "Argument" should be <extAppName>:scanbarcode
globalThis.scanbarcode = function ()
{
    // Open the camera and allow a barcode scan
    _api.Environment.Context.CameraScanBarcodeOpen()
}

function OnOpsBarCodeEvent(sender, args)
{
    if (!args.Handled)
    {
        args.Handled = true;
        
        if (args.BarcodeString != null)
        {
            showMessage('Barcode' + args.BarcodeType +',' + args.BarcodeFormat + ',' + args.BarcodeString + ',' + args.RawBarcodeString );
        }
        else
        {
            showMessage('No Barcode scanned!');
        }
    }

    return _api.Eventing.Continue;
}


function showMessage(msg)
{
    let line = `${_api.Runtime.ApplicationName}: ${msg}`;
    _api.Environment.Context.ShowMessage(line);
}