如何在移动网络应用程序中集成Phonegap插件用于条形码扫描器?

时间:2014-03-14 09:51:20

标签: cordova phonegap-plugins barcode-scanner

我们正在尝试在我们的移动网络应用中集成条码扫描程序的phonegap插件。任何人都可以帮我整合这个吗?

我补充说,Phonegap.js和cardova.js,插件尝试安装,但需要花费很多时间而不是安装..

这是我的HTML内容

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Bar code Reader</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="barcodescanner.js"></script>
<script src="cordova.js"></script>
<script>
$(document).ready(function () {
app.initialize();
});
function clickScan() {
console.log("I am now scanning");
window.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);
});
}
</script>
</head>
<body>
<button id="scan" style="padding: 10px;" onclick="clickScan">Scan!</button>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

按照以下步骤

1.下载并安装Node.js

2.在命令提示符$ sudo npm install -g phonegap

上运行此命令

3.创建名为hello $ phonegap create hello com.example.hello HelloWorld

的应用程序

4.go to hello directory $ cd hello

5.选择你的平台我正在向你展示ios,你也可以为Android构建它

 $ phonegap build ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] compiling iOS...
[phonegap] successfully compiled iOS app

6.add要添加phonegap local plugin add https://github.com/phonegap-build/BarcodeScanner.git

的插件

7.要远程编译您的应用程序,请在build命令前加上附加的远程命令:$ phonegap remote install ios # ...or... $ phonegap remote run ios

答案 1 :(得分:0)

以下是Barcode Scanner插件使用的示例:

<!DOCTYPE HTML>
<html>
<head>
  <title>Barcode Scanner DEMO</title>

<script type="text/javascript" src="plugins/plugin-loader.js"></script>   
<script type="text/javascript" charset="utf-8">

monaca.viewport({width : 320});

function scanBarcode() {
  window.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);
      }
);

}
</script>
</head>

<hr> BarcodeReader DEMO <hr><br>
<input type="button" onClick ="scanBarcode()" value ="Scan" />
</body>
</html>