[SOLVED] Barcodescanner, cordova is not defined

Hello,

I have a project with Framework7 Core and I need to use a barcodescanner system.

I installed this plugins that I found in this forum but I can’t find a clear tutorial about this.

  • I’ve installed this plugin with this command :

phonegap plugin add phonegap-plugin-barcodescanner

And :

plugin name=“phonegap-plugin-barcodescanner” spec=“8.1.0” …

is well added in my config.xml on my cordova folder.

It’s ok.

I have this simple code in my app.js :

 $$('.open-barcode').on('click', function () {

    cordova.plugins.barcodeScanner.scan(
  function (result) {
      alert("We got a barcode\n" +
            "Result: " + result.text + "\n" +
            "Format: " + result.format + "\n" +
            "Cancelled: " + result.cancelled);
  },
  function (error) {
      alert("Scanning failed: " + error);
  },
  {
      preferFrontCamera : true, // iOS and Android
      showFlipCameraButton : true, // iOS and Android
      showTorchButton : true, // iOS and Android
      torchOn: true, // Android, launch with the torch switched on (if available)
      saveHistory: true, // Android, save scan history (default false)
      prompt : "Place a barcode inside the scan area", // Android
      resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
      formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
      orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
      disableAnimations : true, // iOS
      disableSuccessBeep: false // iOS and Android
  }
 );

});

I took this example from the github project.
And when I clic on my open-barcode class, I have this message on my console :

cordova is not defined

I’ve tried with emulator, no result too.

what have I forgotten?

Thank you.

cordova.js included?

I didn’t touch that file.
This cordova.js in \cordova\platforms\android\platform_www ?
what should I do with this file ?

Make sure to include the cordova.js file before calling any cordova functions. Most likely, include this file before index.js file.

Only add:
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>

1 Like

When you can decide the order of calling ?

Where I add this line ?
Index.html ? I have no cordova.js in my path.
I don’t understand, sorry :thinking:

Just add the line shastox says in index.html. Cordova will do the rest

Ok. It works !
Thank you very much to all !