简体   繁体   English

Phonegap 条码扫描器:无法运行

[英]Phonegap barcode scanner: couldn't make it run

I've tried to create a default Phonegap barcode scanner trough plugin basic installation, but it didn't work well.我尝试通过插件基本安装创建默认的 Phonegap 条形码扫描仪,但效果不佳。 I don't know what's happening.我不知道发生了什么。 Here is my code:这是我的代码:

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);
  },
  // deviceready Event Handler
  // The scope of 'this' is the event. In order to call the 'receivedEvent'
  // function, we must explicitly 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);
    console.log('-');
    console.log(cordova);
    console.log('-');
    console.log(cordova.plugins.barcodeScanner);
    console.log('-');
    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);
      }
    );
  }
};

It's basically the default Phonegap plugin panel.它基本上是默认的 Phonegap 插件面板。 The problem is that it doesn't recognize the cordova.plugin.barcodeScanner .问题是它无法识别cordova.plugin.barcodeScanner I've created the project trough the Phonegap Windows tool and ran the cordova plugin add cordova-plugin-statusbar command inside the folder.我已经通过 Phonegap Windows 工具创建了项目,并在文件夹中运行了cordova plugin add cordova-plugin-statusbar命令。 Please help me, I can't see any code example of this working.请帮助我,我看不到此工作的任何代码示例。 Thanks.谢谢。

you can call getScanner() function onClick event in javascript Read More Here您可以在 javascript 中调用 getScanner() 函数 onClick 事件阅读更多

 function getScanner(){
    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);
      }
    ); }

let me know if its not working..让我知道它是否不起作用..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM