Reputation: 51
I have a problem with the plugin barcode scanner.
I use phonegap and cordova (5.0.0) and I try a lot of solutions but anyone worked.
I create a new project, I add platforms android and ios, I add some plugins like camera, dialogs, device and obviously barcode scanner.
I do: cordova build; cordova prepare; cordova serve.
In the index.html I put a button that onclick calls a function.
In the index.js I write the function.
I try it with phonegap on android but it doesn't work.
So I controlled the web-app on firefox with firebug and I noticed that this returns an error:
cordova is not defined
The js are included as follows:
- cordova.js
- barcodescanner.js
- index.js (that contain the function for the scanner)
You can see more details about my problem on this link:
cordova plugin barcode scanner doesn't open the scan
Even if I change the code, the code crashes always after "cordova.plugins.barcodeScanner.scan".
It seems like the object doesn't exist or the plugin isn't included correctly.
I'm sure that the plugin is installed correctly.
I hope there's someone who can help me.
Thank you so much to everyone.
Upvotes: 0
Views: 1742
Reputation: 202
In order for the plug-ins to actually work, you need to add two main scripts first.
HTML code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
Next, you need to make sure that the device ready event actually fires or else none will work. By default, Cordova will create the index.js so open it inside your editor and delete everything that is written there and write this.
index.js:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady () {
// your code here
}
When you finish writing your code, type cordova prepare
then cordova emulate
and you will see the plug-ins working on your mobile phone.
Upvotes: 1