ti.barcode icon indicating copy to clipboard operation
ti.barcode copied to clipboard

'success' event not called when code is scanned

Open TimDorand opened this issue 7 years ago • 6 comments

Barcode.addEventListener('success', function(e) {
Ti.alert('test');
// is not called when the code is scanned
}

Ti sdk v 7.2.0.GA

TimDorand avatar Aug 21 '18 15:08 TimDorand

Do you use module v2.0.2? And maybe you use the deprecated kroll-thread? cc @vijaysingh-axway

hansemannn avatar Aug 21 '18 15:08 hansemannn

I’m using the android module v4.0.1

TimDorand avatar Aug 21 '18 15:08 TimDorand

cc @m1ga then!

hansemannn avatar Aug 21 '18 16:08 hansemannn

var winSample = Ti.UI.createWindow({title: 'sample'});

var Barcode = require('ti.barcode');

var buttonScan = Titanium.UI.createButton({	title: 'scan barcode or qrcode'});
winSample.add(buttonScan);
winSample.open();

buttonScan.addEventListener('click', function() {
	Barcode.addEventListener('error', function(e) {
		Ti.UI.createAlertDialog({
			cancel: 0,
			buttonNames: ['OK'],
			title: 'Scanning Error',
			message: 'Error while scanning. Error: ' + e.message
		}).show();
	});
	Barcode.addEventListener('cancel', function(e) {
		Barcode.cancel();
		Ti.API.info('Cancel received');
	});
	Barcode.addEventListener('success', function(e) {
		if (e != undefined && e.result != undefined) {
			var scanResult = e.result.toUpperCase().trim();
			console.log(e.format + ' barcode ' + scanResult);
		}
	});
	Barcode.capture({
		showCancel: true,
		showRectangle: true,
		keepOpen: true
	});
});

works fine for me in 7.2.0.GA and ti.barcode 4.0.1.

Even the alert works, but it is behind the camera window, so you only see it when you close the camera activity

m1ga avatar Aug 21 '18 16:08 m1ga

Thanks putting the event listener in the click event listener function make it work.

buttonScan.addEventListener('click', function() {
	Barcode.addEventListener('success', function(e) {
		if (e != undefined && e.result != undefined) {
			var scanResult = e.result.toUpperCase().trim();
			console.log(e.format + ' barcode ' + scanResult);
		}
	});
	Barcode.capture({
		showCancel: true,
		showRectangle: true,
		keepOpen: true
	});
});

Still have a strange issue: the android previous button is doesn't close the scan in the first place. It's like there is two camera activity.

TimDorand avatar Aug 22 '18 14:08 TimDorand

are you sure that you are not opening two cameras? Put a console.log() inside the click event to check if its only called once. Don't have that problem in my example above

m1ga avatar Aug 22 '18 17:08 m1ga