I am programming my app in Brackets and then zipping it up and uploading it to PhoneGap build for building my iPhone and Android installers.
So far I have added this line of code to my config.xml:
I then create a page in my app with this code:
alert("scan open");
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);
}
);
And just my first alert showing "scan open" pops up, I never get any barcode scanner on Android. Am I missing any steps?
So far I have added this line of code to my config.xml:
I then create a page in my app with this code:
alert("scan open");
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);
}
);
And just my first alert showing "scan open" pops up, I never get any barcode scanner on Android. Am I missing any steps?
- 23 Posts
- 1 Reply Like
- frustrated
Posted 5 years ago
- 1840 Posts
- 78 Reply Likes
ryan, Developer
- 1538 Posts
- 132 Reply Likes
Did you add the barcodescanner plugin to your config.xml file?
<gap:plugin name="phonegap-plugin-barcodescanner" source="npm" />- 23 Posts
- 1 Reply Like
So when ever I post the xml it takes it out of the comment, here it is without the arrows:
gap:plugin name="com.phonegap.plugins.barcodescanner" version="2.2.0"
gap:plugin name="com.phonegap.plugins.barcodescanner" version="2.2.0"
ryan, Developer
- 1538 Posts
- 132 Reply Likes
Thats an older version, but should still work. see response below.
- 23 Posts
- 1 Reply Like
Which is a newer version that I should use?
ryan, Developer
- 1538 Posts
- 132 Reply Likes
I notice that you're running your code on document.ready -- use deviceready instead for phonegap applications:
Might even be better to activate the scanner on a button click to be sure the plugin has initialized.
$(document).on('deviceready', function() {
...
Might even be better to activate the scanner on a button click to be sure the plugin has initialized.
- 23 Posts
- 1 Reply Like
Awesome About to try this out! Will deviceready change any other functionality?
- 23 Posts
- 1 Reply Like
So I tried this and it did not work... You can look at the build right now that is online.
- 48 Posts
- 0 Reply Likes
Have you added phonegap.js at the top ?
- 23 Posts
- 1 Reply Like
I do not have a phonegap.js in my html page. Are you talking about my scan.html page or my config.xml?
ryan, Developer
- 1538 Posts
- 132 Reply Likes
ah yes. any html page that utilizes device functionality (such as the barcodescanner) needs to include cordova.js (or phonegap.js, same effect):
not having this will result in the barcodescanner being unavailable, and also the deviceready event won't fire.
Possibly helpful: https://github.com/wildabeast/Barcode...
also I'd recommend checking out chrome remote debugger -- helps to debug issues like this.
<script src="cordova.js"></script>
not having this will result in the barcodescanner being unavailable, and also the deviceready event won't fire.
Possibly helpful: https://github.com/wildabeast/Barcode...
also I'd recommend checking out chrome remote debugger -- helps to debug issues like this.
- 23 Posts
- 1 Reply Like
Where can I download the cordova.js file?
- 23 Posts
- 1 Reply Like
Figured it out, the compiler adds it automatically! Now I can start using plugins!
ryan, Developer
- 1538 Posts
- 132 Reply Likes
Related Categories
-
PhoneGap Build
- 15111 Conversations
- 275 Followers
-
Plugins
- 1283 Conversations
- 38 Followers




searayman
ryan, Developer
searayman
ryan, Developer
searayman