Fuente de descarga de plugin:
https://github.com/wildabeast/BarcodeScanner
$ cordova platform add android
$ cordova platform add ios
$cordova build
$cordova -d plugin add /aqui el directorio donde se descargo el puglin/BarcodeScanner-master
Revisar que los xml, js apropiados esten el www general del proyecto.
La estructura del proyecto es:
Para esta app es:
barcodesacanner.js (Archivo viene el directorio del plugin)
cordova.js (archivo que se crea al momento de hacer build)
/***************************************************************************/
cordova_plugins.js (Verificamos que el archivo contenga la info del plugin, sino lo creamos.)
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"file": "plugins/com.phonegap.plugins.barcodescanner/www/barcodescanner.js",
"id": "com.phonegap.plugins.barcodescanner.BarcodeScanner",
"clobbers": [
"cordova.plugins.barcodeScanner"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"com.phonegap.plugins.barcodescanner": "2.2.0"
}
// BOTTOM OF METADATA
});
/***************************************************************************/
config.xml (Info de la app e info de plugin)
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.qr" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Barcode</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<feature name="BarcodeScanner">
<param name="package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
<content src="index.html" />
<access origin="*" />
</widget>
index.js
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// `load`, `deviceready`, `offline`, and `online`.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById('scan').addEventListener('click', this.scan, false);
document.getElementById('encode').addEventListener('click', this.encode, false);
},
// deviceready Event Handler
//
// The scope of `this` is the event. In order to call the `receivedEvent`
// function, we must explicity call `app.receivedEvent(...);`
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
scan: function() {
console.log('scanning');
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan( function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
console.log("Scanner result: \n" +
"text: " + result.text + "\n" +
"format: " + result.format + "\n" +
"cancelled: " + result.cancelled + "\n");
document.getElementById("info").innerHTML = result.text;
console.log(result);
/*
if (args.format == "QR_CODE") {
window.plugins.childBrowser.showWebPage(args.text, { showLocationBar: false });
}
*/
}, function (error) {
console.log("Scanning failed: ", error);
} );
},
encode: function() {
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.google.com", function(success) {
alert("encode success: " + success);
}, function(fail) {
alert("encoding failed: " + fail);
}
);
}
};
Fuente de ejemplo:
https://github.com/wildabeast/BarcodeDemo
