Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 条形码扫描仪-Cordova插件_Android_Eclipse_Cordova_Barcode Scanner - Fatal编程技术网

Android 条形码扫描仪-Cordova插件

Android 条形码扫描仪-Cordova插件,android,eclipse,cordova,barcode-scanner,Android,Eclipse,Cordova,Barcode Scanner,我在Android应用程序中使用了PhoneGap插件条形码扫描仪。当我将函数window.plugins.barcodeScanner.encode和window.plugins.barcodeScanner.scan附加到按钮上的onclick事件时,它们工作得非常好 但是,当我尝试在body/page init/page show event的onload事件上执行encode函数时,我在Eclipse中遇到以下错误 Uncaught TypeError: Cannot call meth

我在Android应用程序中使用了PhoneGap插件条形码扫描仪。当我将函数
window.plugins.barcodeScanner.encode
window.plugins.barcodeScanner.scan
附加到按钮上的onclick事件时,它们工作得非常好

但是,当我尝试在body/page init/page show event的onload事件上执行encode函数时,我在Eclipse中遇到以下错误

Uncaught TypeError: Cannot call method 'encode' of undefined at file:///android_asset/www/indexx.html:32

谢谢。

在Cordova完成加载后尝试调用该方法(deviceready事件)

您正在使用哪个版本的phonegap?1.9.0还是2.0.0

2.0.0提供了调用插件的新方法。 在上,您将使用:

window.plugins.barcodeScanner.scan( function(result) {
    ...
    ..
}
如果您使用的是2.0.0,请尝试另一种初始化插件的方法:

window.barcodeScanner = new BarcodeScanner();

function scanBarcode()
{
    window.barcodeScanner.scan(function(result) {
        alert("We got a barcode\n" +
              "Result: " + result.text + "\n" +
              "Format: " + result.format); 
    }, function(error) {
        alert("Error scanning Barcode: " + error);
    });
}

我对科尔多瓦还不熟悉,但根据我所看到的,听起来“Traumales”是正确的。要在Cordova完成加载后调用window.plugins.barcodeScanner.encode或window.plugins.barcodeScanner.scan函数,请在javascript文件中执行以下操作:

// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
  // As an example, you now have the device name, Cordova version, etc. available
  alert('Device Name: ' + device.name);
  alert('Device Cordova: ' + device.cordova);
  alert('Device Platform: ' + device.platform);
  alert('Device UUID: ' + device.uuid);
  alert('Device Version: ' + device.version);

  // Now call one of your barcode functions, etc.
}
有关更多信息,请参阅