2014-05-12 27 views
0

我正在使用PhoneGap版本和chariotsolutions NFC插件来扫描NFC卡,它正在工作。但是,它在PhoneGap构建关闭后开始失败。我只能猜测,PhoneGap构建现在使用更新版本的插件。干净的版本仍然会在内部扫描卡时崩溃。chariotsolutions phonegap-nfc插件重新启动扫描

我用最新版本创建了一个新的Cordova项目,使用cordova CLI,并安装了chariotsolutions插件。目前只有熊骨头项目仍在失败,这个项目现在不在PhoneGap版本中。

硬件和软件:的Android的Nexus 7上运行的是Android 4.4.2 科尔多瓦版本3.3

熊骨头项目代码只包含这个onDeviceReady:

initialize: function() { 
    this.bindEvents(); 
}, 
// Bind Event Listeners 
bindEvents: function() { 
    document.addEventListener('deviceready', this.onDeviceReady, false); 
}, 
onDeviceReady: function() { 
console.log('v0.0.3'); 

document.addEventListener('resume', app.resume, false); 
document.addEventListener('pause', app.pause, false); 

// Read NDEF formatted NFC Tags 
nfc.addNdefListener (
    function (nfcEvent) { 
    console.log('nfcEvent '+JSON.stringify(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 
    console.log(JSON.stringify(ndefMessage)); 

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

}, 

上发布的亚行输出应用:

I/ActivityManager( 512): Start proc com.test.myapp for activity com.test.myapp/.myappname: pid=17325 uid=10037 gids={50037, 3003} 
I/CordovaLog(17325): Changing log level to DEBUG(3) 
I/CordovaLog(17325): Found start page location: index.html 
D/Whitelist(17325): Unlimited access to network resources 
D/CordovaActivity(17325): CordovaActivity.onCreate() 
V/WebViewChromium(17325): Binding Chromium to the background looper Looper (main, tid 1) {4211c938} 
I/chromium(17325): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0 
I/BrowserProcessMain(17325): Initializing chromium process, renderers=0 
W/chromium(17325): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation 
D/libEGL (17325): loaded /system/lib/egl/libEGL_tegra.so 
D/libEGL (17325): loaded /system/lib/egl/libGLESv1_CM_tegra.so 
D/libEGL (17325): loaded /system/lib/egl/libGLESv2_tegra.so 
D/CordovaWebView(17325): CordovaWebView is running on device made by: asus 
D/JsMessageQueue(17325): Set native->JS mode to 2 
D/CordovaActivity(17325): CordovaActivity.init() 
D/CordovaWebView(17325): >>> loadUrl(file:///android_asset/www/index.html) 
D/PluginManager(17325): init() 
D/CordovaWebView(17325): >>> loadUrlNow() 
I/CordovaLog(17325): Changing log level to DEBUG(3) 
I/CordovaLog(17325): Found start page location: index.html 
D/Whitelist(17325): Unlimited access to network resources 
D/CordovaActivity(17325): Resuming the App 
D/CordovaActivity(17325): CB-3064: The errorUrl is null 
D/SoftKeyboardDetect(17325): Ignore this event 
D/OpenGLRenderer(17325): Enabling debug mode 0 
D/SoftKeyboardDetect(17325): Ignore this event 
I/ActivityManager( 512): Displayed com.test.myapp/.myappname: +813ms 
D/AndroidRuntime(17309): Shutting down VM 
D/dalvikvm(17309): GC_CONCURRENT freed 97K, 15% free 589K/688K, paused 0ms+2ms, total 5ms 
D/CordovaActivity(17325): onMessage(onPageStarted,file:///android_asset/www/index.html) 
D/CordovaLog(17325): file:///android_asset/www/index.html: Line 25 : Viewport target-densitydpi is not supported. 
I/chromium(17325): [INFO:CONSOLE(25)] "Viewport target-densitydpi is not supported.", source: file:///android_asset/www/index.html (25) 
D/CordovaWebViewClient(17325): onPageFinished(file:///android_asset/www/index.html) 
D/CordovaActivity(17325): onMessage(onPageFinished,file:///android_asset/www/index.html) 
D/CordovaActivity(17325): onMessage(spinner,stop) 
D/CordovaNetworkManager(17325): Connection Type: wifi 
I/chromium(17325): [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported 
I/chromium(17325): [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported 
D/CordovaNetworkManager(17325): Connection Type: wifi 
D/CordovaActivity(17325): onMessage(networkconnection,wifi) 
D/CordovaLog(17325): file:///android_asset/www/js/index.js: Line 58 : onDeviceReady v0.0.3 
I/chromium(17325): [INFO:CONSOLE(58)] "onDeviceReady v0.0.3", source: file:///android_asset/www/js/index.js (58) 
D/NfcPlugin(17325): execute registerNdef 
D/CordovaLog(17325): file:///android_asset/www/js/index.js: Line 83 : Waiting for NDEF tag 
I/chromium(17325): [INFO:CONSOLE(83)] "Waiting for NDEF tag", source: file:///android_asset/www/js/index.js (83) 
D/NfcPlugin(17325): execute init 
D/NfcPlugin(17325): Enabling plugin Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.test.myapp/.myappname } 
D/NfcDispatcher( 769): Set Foreground Dispatch 
D/NfcPlugin(17325): parseMessage Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.test.myapp/.myappname } 
D/NfcPlugin(17325): action android.intent.action.MAIN 
D/CordovaLog(17325): file:///android_asset/www/plugins/com.chariotsolutions.nfc.plugin/www/phonegap-nfc.js: Line 18 : Initialized the NfcPlugin 
I/chromium(17325): [INFO:CONSOLE(18)] "Initialized the NfcPlugin", source: file:///android_asset/www/plugins/com.chariotsolutions.nfc.plugin/www/phonegap-nfc.js (18) 
D/CordovaActivity(17325): onMessage(spinner,stop) 

亚行当我扫描一张卡时输出。似乎由于某种原因暂停应用matched single TECH,然后重新加载Cordova再次运行onDeviceReady。

D/NativeNfcTag( 769): Check NDEF Failed - status = 255 
D/NativeNfcTag( 769): Check NDEF Failed - status = 255 
D/NfcDispatcher( 769): dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable] message: null 
I/ActivityManager( 512): START u0 {flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras)} from pid 769 
D/dalvikvm( 512): GC_FOR_ALLOC freed 564K, 15% free 18611K/21744K, paused 145ms, total 145ms 
D/dalvikvm( 512): GC_FOR_ALLOC freed 283K, 15% free 18573K/21744K, paused 144ms, total 144ms 
I/NfcDispatcher( 769): matched single TECH 
D/CordovaActivity(17325): Paused the application! 
D/CordovaWebView(17325): Handle the pause 
D/NfcPlugin(17325): onPause Intent { } 
D/NfcPlugin(17325): stopNfc 
D/NfcDispatcher( 769): Set Foreground Dispatch 
D/CordovaLog(17325): file:///android_asset/www/js/index.js: Line 48 : -- pause event fired -- 
I/chromium(17325): [INFO:CONSOLE(48)] "-- pause event fired -- ", source: file:///android_asset/www/js/index.js (48) 
I/ActivityManager( 512): START u0 {act=android.nfc.action.TECH_DISCOVERED cmp=com.widgapp.NFC_ReTAG_FREE/com.widgapp.NFC_ReTag_dispatch_other (has extras)} from pid 769 
V/receiver Tag discovered: (15520): TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable] mifare tagid: 8A0924F9 
I/ActivityManager( 512): START u0 {flg=0x4000000 cmp=com.widgapp.NFC_ReTAG_FREE/.automode (has extras)} from pid 15520 
D/NfcDispatcher( 769): Set Foreground Dispatch 
D/NfcDispatcher( 769): Set Foreground Dispatch 
D/dalvikvm(15520): GC_CONCURRENT freed 224K, 4% free 7810K/8072K, paused 4ms+3ms, total 42ms 
W/InputMethodManagerService( 512): Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected] 
I/CordovaLog(17325): Changing log level to DEBUG(3) 
I/CordovaLog(17325): Found start page location: index.html 
D/Whitelist(17325): Unlimited access to network resources 
D/CordovaActivity(17325): Resuming the App 
D/CordovaActivity(17325): CB-3064: The errorUrl is null 
D/NfcPlugin(17325): onResume Intent { } 
D/NfcDispatcher( 769): Set Foreground Dispatch 
D/CordovaLog(17325): file:///android_asset/www/js/index.js: Line 41 : -- resume event fired -- 
I/chromium(17325): [INFO:CONSOLE(41)] "-- resume event fired -- ", source: file:///android_asset/www/js/index.js (41) 
D/NativeNfcTag( 769): Tag lost, restarting polling loop 
D/dalvikvm(15037): GC_CONCURRENT freed 475K, 7% free 8271K/8824K, paused 3ms+4ms, total 40ms 
D/dalvikvm(15037): WAIT_FOR_CONCURRENT_GC blocked 30ms 
D/Finsky (15037): [1] 5.onFinished: Installation state replication succeeded. 

任何帮助,将不胜感激。

回答

2

它不工作的原因是因为应用程序正在查找NDEF标记,但是您正在扫描非NDEF标记。

D/NativeNfcTag( 769): Check NDEF Failed - status = 255 
D/NativeNfcTag( 769): Check NDEF Failed - status = 255 
D/NfcDispatcher( 769): dispatch tag: TAG: Tech [android.nfc.tech.MifareClassic, android.nfc.tech.NfcA, android.nfc.tech.NdefFormatable] message: null 

要读取非NDEF代码,您需要添加nfc.addNdefFormatableListenernfc.addTagDiscoveredListener。您可以使用一个事件处理程序,例如app.onNFC,适用于多种标签类型。

您也可以使用NXP Tag Writer向标签写入消息,该标签也将其格式化为NDEF。

请注意,使用Broadcom NFC芯片组的设备不会阅读Mifare Classic标签,因此即使在Mifare Classic标签上阅读NDEF消息时,您也可能会收到有关非NDEF消息的错误。

我的Nexus 7(原始版本)具有恩智浦NFC芯片组。在我删除console.log('nfcEvent '+JSON.stringify(nfcEvent));之后,您的代码正常工作。由于循环引用,该事件不能字符串化。我认为第二代Nexus 7使用Broadcom NFC芯片组。