'success' event not called when code is scanned
Barcode.addEventListener('success', function(e) {
Ti.alert('test');
// is not called when the code is scanned
}
Ti sdk v 7.2.0.GA
Do you use module v2.0.2? And maybe you use the deprecated kroll-thread? cc @vijaysingh-axway
I’m using the android module v4.0.1
cc @m1ga then!
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
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.
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