Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Maxim_K_
Beginner
92 Views

BarcodeScenner doesn't work

Hello everyone!

I've installed the BarcodeScanner from the interface of Intel XDK. But every time I try to use the code of example follow by the official documentation it give me the error: "There is no handler for the following exec call: BarcodeScanner.scan". Could you help me to solve the issue? Thank you.

Tags (2)
0 Kudos
6 Replies
Diego_Calp
Valued Contributor I
92 Views

 

Hello,

 

I have an app with barcode scanner plugin working perfectly to scan QR and barcodes.

BarcodeScanner is version 4.1.0

You also need Camera plugin.

My code is very simple, at a button click, call this function:

function scanCP(){
	cordova.plugins.barcodeScanner.scan(
    	function (result) {
			if(result.text.length !== 12){
				bootbox.alert("Error al leer el código, intente nuevamente");
			}else{
				$("#i_numerocp").val(result.text);
			}
    	},
    	function (error) {
        	bootbox.alert("Error en el escaneo del Nº de Carta de Porte: " + error);
    	}, 
		{//opciones varias
			//"preferFrontCamera": true, // iOS and Android
			//"showFlipCameraButton": true, // iOS and Android
			//"prompt": "Place a barcode inside the scan area", // supported on Android only
			"formats": "CODE_128" // default: all but PDF_417 and RSS_EXPANDED
			//"orientation": "landscape" // Android only (portrait|landscape), default unset so it rotates with the device
		}
	);	
}

This opens the device camera to get the bar code image.

Don't pay attention to bootbox, is just a lib to show alerts and dialogs.

I can't say nothing about the error, I have this working very easily, no problems at all.

NOTE: after write all this I tested my app with XDK 3522 first time. The new Simulator give your error, did you test your app from App Preview or generating an APK?

Regards

Diego

 

Maxim_K_
Beginner
92 Views

Dear Diego,

Thank you for answer! The problem is that the code from the example work well on AndroidOS but doesn't work at all on iOS. The camera even doesn't start. Any ideas? P.S. I check by Intel App Preview only.

Hamilton_Tenório_da_
Valued Contributor I
92 Views

Maxim> insert this code in you JS file. Maybe there is an error in other point before the barcode call. I had some problems with errors in iOS that doens´t happens in Android.

 

//ativar em caso de necessidade de entender algum erro
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
    analytics.sendAppView('Erro script: ' + errorMsg + url + lineNumber); 
    alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber + ' Column: ' + column + ' StackTrace: ' +  errorObj);
 };

Hamilton

Diego_Calp
Valued Contributor I
92 Views

Maxim,

I can confirm that my code works fine on iOS App Preview and Android, App Preview and as APK.

Regards

DIego

Maxim_K_
Beginner
92 Views

Thanks a lot to all of you! Now the scanner is working well. The problem was with the rights to the camera on iOS.

Kayla_H_
Beginner
92 Views

Can anyone help me with my coding. I am still receiving the "There is no handler for the  exe call BarcodeScanner.scan" how do I fix this problem? my code is below. PLEASE HELP!

/*

 * Please see the included README.md file for license terms and conditions.

 */





// This file is a suggested starting place for your code.

// It is completely optional and not required.

// Note the reference that includes it in the index.html file.





/*jslint browser:true, devel:true, white:true, vars:true */

/*global $:false, intel:false app:false, dev:false, cordova:false */







// This file contains your event handlers, the center of your application.

// NOTE: see app.initEvents() in init-app.js for event handler initialization code.

//ativar em caso de necessidade de entender algum erro
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
    analytics.sendAppView('Erro script: ' + errorMsg + url + lineNumber); 
    alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber + ' Column: ' + column + ' StackTrace: ' +  errorObj);
 };

function myEventHandler() {

    "use strict";



    var ua = navigator.userAgent;

    var str;



    if (window.Cordova && dev.isDeviceReady.c_cordova_ready__) {

        str = "It worked! Cordova device ready detected at " + dev.isDeviceReady.c_cordova_ready__ + " milliseconds!";

    } else if (window.intel && intel.xdk && dev.isDeviceReady.d_xdk_ready______) {

        str = "It worked! Intel XDK device ready detected at " + dev.isDeviceReady.d_xdk_ready______ + " milliseconds!";

    } else {

        str = "Bad device ready, or none available because we're running in a browser.";

    }



    console.log(str);

}





// ...additional event handlers here...



function thirdPartyEmulator() {

    alert("This feature uses a third party barcode scanner plugin. Third party plugins are not supported on emulator or app preview. Please build app to test.");

}



function scan() {

    "use strict";

    var fName = "scan():";

    console.log(fName, "entry");

    try {

        if (window.tinyHippos) {

            thirdPartyEmulator();

            console.log(fName, "emulator alert");

        } else {

            cordova.plugins.barcodeScanner.scan(

                function (result) {

                    console.log(fName, "Scanned result found!");

                    alert("We got a barcode!\n" +

                        "Result: " + result.text + "\n" +

                        "Format: " + result.format + "\n" +

                        "Cancelled: " + result.cancelled + "\n\n" +

                        "You may use the " + result.format + " - '" + result.text + "' to look up your product in any UPC database like http://www.upcdatabase.com/");

                },

                function (error) {

                    alert("Scanning failed: " + error);

                }

            );

        }

    } catch (e) {

        console.log(fName, "catch, failure");

    }



    console.log(fName, "exit");

}

 

 

Reply