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:
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;
.Eventing.SubscribeToEvent('OpsBarcodePreviewEvent', OnOpsBarCodeEvent); _api
The Barcode Scanner event follows the standard SIM event method
signature. The args are of type
OpsBarcodePreviewEventArgs
.
function OnOpsBarCodeEvent(sender, args)
{if (!args.Handled)
{.Handled = true;
args
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. |
This feature is only available for Android devices with camera.
var _api = SimphonyExtensibilityAPI;
.Eventing.SubscribeToEvent('OpsBarcodePreviewEvent', OnOpsBarCodeEvent);
_api
//The button should be configured as Function | Sim Inquire. The button "Argument" should be <extAppName>:scanbarcode
.scanbarcode = function ()
globalThis
{// Open the camera and allow a barcode scan
.Environment.Context.CameraScanBarcodeOpen()
_api
}
function OnOpsBarCodeEvent(sender, args)
{if (!args.Handled)
{.Handled = true;
args
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}`;
.Environment.Context.ShowMessage(line);
_api }