首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Phonegap,没有在android上工作的条形码扫描仪

Phonegap,没有在android上工作的条形码扫描仪
EN

Stack Overflow用户
提问于 2014-03-11 01:54:11
回答 1查看 923关注 0票数 1

我已经做了以下工作来安装和使用条形码扫描仪。

代码语言:javascript
运行
复制
>phonegap plugin add https://github.com/jonathannaguin/BarcodeScanner

这成功地在phonegap/plugins目录中安装了条形码扫描器插件。

然后我就像这样为android做的

代码语言:javascript
运行
复制
phonegap build android

这也成功地完成了。然后,我使用文本字段上的处理程序将其放入感应器触摸应用程序中。但是当油田被开发时,就没有结果了。什么都没发生。

代码语言:javascript
运行
复制
Ext.define("Tasks.view.BarcodeField", {
extend: 'Ext.Container',
alias:'widget.barcodeField',

xtype: 'barcodefield',

config: {    
    layout: 'hbox',
    id: 'barcodeField',
    itemId: 'barcodeField',
    items: [
        {
            xtype: 'textfield',
            label: 'Barcode',
            labelWidth: '37.4%',                            
            flex: 4        
        },
        {
            xtype: 'image',
            id : 'barcodeScanner',
            itemId : 'barcodeScanner',
            src: 'resources/images/barcodes.png',
            padding: '6 0 0 0',
            flex: 1,
            listeners: {
                tap: function() {
                    console.log("Starting the barcode Scanner");
                    function success(result) {
                         alert("We got a barcode\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled);
                    }

                    function fail(error) {
                          alert("Scanning failed: " + error);
                    }

                     cordova.plugins.barcodeScanner.scan(success, fail);
                }
            }               
        }        
    ]        
},

getValue : function() 
{   
    console.log(this.getItems().getAt(0).getValue());
    return this.getItems().getAt(0).getValue();
},
setValue : function(newvalue) {
   this.getItems().getAt(0).setValue(newvalue);
}

});

我看到tap处理程序正在被调用,日志语句在控制台上被调用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-11 17:10:52

我调用条形码插件如下,它正在工作。我没有调用cordova.plugins,而是使用了window.plugins,它可以工作。

代码语言:javascript
运行
复制
Ext.define("Tasks.view.BarcodeField", {
extend: 'Ext.Container',
alias:'widget.barcodeField',

xtype: 'barcodefield',

config: {    
    layout: 'hbox',
    id: 'barcodeField',
    itemId: 'barcodeField',
    items: [
        {
            xtype: 'textfield',
            label: 'Barcode',
            labelWidth: '37.4%',                            
            flex: 4        
        },
        {
            xtype: 'image',
            id : 'barcodeScanner',
            itemId : 'barcodeScanner',
            src: 'resources/images/barcodes.png',
            padding: '6 0 0 0',
            flex: 1,
            listeners: {
                tap: function() {
                    console.log("Starting the barcode Scanner");
                    function success(result) {
                         alert("We got a barcode\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled);
                    }

                    function fail(error) {
                          alert("Scanning failed: " + error);
                    }
                    window.plugins.barcodeScanner.scan(success, fail);
                    // cordova.plugins.barcodeScanner.scan(success, fail);
                }
            }               
        }        
    ]        
},

getValue : function() 
{   
    console.log(this.getItems().getAt(0).getValue());
    return this.getItems().getAt(0).getValue();
},
setValue : function(newvalue) {
   this.getItems().getAt(0).setValue(newvalue);
}

});

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22314946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档