Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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 条形码扫描仪phonegap插件问题_Android_Cordova - Fatal编程技术网

Android 条形码扫描仪phonegap插件问题

Android 条形码扫描仪phonegap插件问题,android,cordova,Android,Cordova,我目前正试图在我的phonegap项目中实现条形码扫描仪。 但我完全迷路了,因为我读了很多关于barecodescanner的主题,所有可能的解决方案都不适合我 首先,一些教程和文档说我必须使用 cordova.plugin.barcodeScanner.scan(…)。但对我来说,cordova.plugin总是未定义的 有些人说我必须做cordova.require(“cordova/plugin/BarcodeScanner”);它不工作,当我运行我的应用程序时,我得到以下错误:“找不到模

我目前正试图在我的phonegap项目中实现条形码扫描仪。 但我完全迷路了,因为我读了很多关于barecodescanner的主题,所有可能的解决方案都不适合我

首先,一些教程和文档说我必须使用 cordova.plugin.barcodeScanner.scan(…)。但对我来说,cordova.plugin总是未定义的


有些人说我必须做cordova.require(“cordova/plugin/BarcodeScanner”);它不工作,当我运行我的应用程序时,我得到以下错误:“找不到模块”cordova/plugin/BarcodeScanner“。

如果使用PhoneGap构建…这是一个实现示例

在config.xml文件中添加以下行:

<!-- We'll include the Barcode plugin  -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />

然后在index.html文件中:

<script type="text/javascript">
function Scan() {
    cordova.plugins.barcodeScanner.scan(
      function (result) {
          window.open(result.text,'_self', 'location=no') //Opens URL in browser
          //alert("We got a barcode\n" +
          //      "Result: " + result.text + "\n" +
          //      "Format: " + result.format + "\n" +
          //      "Cancelled: " + result.cancelled);
      }, 
      function (error) {
          alert("Scanning failed: " + error);
      }
    );
}
</script>

函数扫描(){
cordova.plugins.barcodeScanner.scan(
功能(结果){
window.open(result.text,''u self','location=no')//在浏览器中打开URL
//警报(“我们得到了一个条形码\n”+
//结果:“+Result.text+”\n+
//格式:“+result.Format+”\n+
//“已取消:“+结果.已取消”);
}, 
函数(错误){
警报(“扫描失败:+错误”);
}
);
}
要使用页面正文部分中的按钮调用脚本,请执行以下操作:

<button onclick="Scan()">Barcode</button>
条形码

祝你好运!

你安装插件了吗?你是如何构建你的项目的?哪个phonegap/cordova版本?