cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Barcode Listener

Former Member
0 Kudos

Hi I just developed a UI5 application (acceded through the Fiori LPD) that requires bar code scanning. For this I used a regular button:

<Button icon="sap-icon://bar-code" id="buttonScan" press="onPressScan" visible="{device>/system/phone}" />

And in the "press" action I used the code:

onPressScan: function (oEvent) {
	sap.ndc.BarcodeScanner.scan(
		function (mResult) {
			if (!mResult.cancelled && mResult.text.length > 0) {//action}
		},
		function (sError) {//error handling},
		function (mLive) {
			if (mLive.newValue && mLive.newValue.length > 0) {//action}
		}
	);
}

It works nice using the SAP Fiori Client, accessing the device's camera after tapping over the scan button.

The thing is: The customer is using iPods with a barcode sleeve (I don't know which brand) and they want to capture the scanned value and pass it to the application without tapping the button.

Is it possible to implement something like a listener to catch the barcode sleeve scanned value into my app?

Regards,

Gregory Mayorga

Accepted Solutions (1)

Accepted Solutions (1)

Diegoborja
Explorer
0 Kudos

Hi Gregory,

Short answer is yes, but you first need to know which sleeve model your customer is using because you need to get your hands on the right cordova plugin to connect to the sleeve hardware. For instance, one of our clients uses the Linea Pro and they provide an iOS cordova plugin. With that you will need to create a custom Fiori client and add the aforementioned plugin. The plugin API will most likely have a method to add a listener to the "scan" event where you can put your business logic. The logic to get it working once you have your custom Fiori client done is very simple, something like the code below. In this case, Infinea is the Javascript object that comes with the plugin for the Linea Pro

/** 
 * Default Infinea - Overwrite this method for other
 */
initialiseBarcodeScanner: function () {
	if (window.Infinea) {
		window.Infinea.init();
	}
},

/** 
 * Default Infinea - Overwrite this method for other
 */
destroyBarcodeScanner: function () {
	if (window.Infinea) {
		window.Infinea.barcodeDataCallback = null;
	}
},

/** 
 * Default Infinea - Overwrite this method for other
 */
addBarcodeHandler: function (fScanSuccess) {
	if (window.Infinea) {
		window.Infinea.barcodeDataCallback = function (sBarcode, sType, sTypeText) {
			var oResult = {
				text: sBarcode
			};
			fScanSuccess(oResult);
		}.bind(this);
	}
}

I hope this information helps,

Good luck,

Diego

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

My customer is using a Linea Pro sleeve scanner and I managed to solve this issue with something like the recommendation of diego.borja.


Regards,

Gregory Mayorga.