【问题标题】:NFC reader apache cordovaNFC阅读器阿帕奇科尔多瓦
【发布时间】:2016-03-15 08:30:58
【问题描述】:

我想用 phonegap nfc (Tutorial phonegap) 读取 nfc 卡,但活动没有启动

这是 index.js 的代码

 onDeviceReady: function() {
     app.receivedEvent('deviceready');

// Read NDEF formatted NFC Tags
nfc.addNdefListener (
    function (nfcEvent) {
        var tag = nfcEvent.tag,
            ndefMessage = tag.ndefMessage;

        // dump the raw json of the message
        // note: real code will need to decode
        // the payload from each record
        alert(JSON.stringify(ndefMessage));

        // assuming the first record in the message has
        // a payload that can be converted to a string.
        alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
    },
    function () { // success callback
        alert("Waiting for NDEF tag");
    },
    function (error) { // error callback
        alert("Error adding NDEF listener " + JSON.stringify(error));
    }
);
},

有什么建议吗?

【问题讨论】:

  • 您是在打开应用程序的情况下尝试阅读吗?控制台或警报中有任何输出吗?

标签: javascript android angularjs cordova phonegap-plugins


【解决方案1】:

nfc.addTagDiscoveredListener 代替 nfc.addNdefListener

解决

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多