2015-06-19 223 views
1

我想搭建一個測試科爾多瓦應用程序來讀取和寫入針對Windows手機和Android手機的NFC標籤。 將測試應用程序部署到設備時,在Android上,當嘗試註冊偵聽器時,出現一條錯誤消息,提示「類未找到」。在Windows手機上,我什麼也得不到。科爾多瓦NFC插件不工作

以下是我以前使用的科爾多瓦CLI

創建一個科爾多瓦應用

新增平臺

添加插件(https://github.com/chariotsolutions/phonegap-nfc.git

添加以下代碼來創建應用程序的步驟替換index.js文件中的deviceready

try { 
     // 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)); 
      } 
     ); 
    } catch (ex) { 
     alert(ex.message); 
    } 


    app.receivedEvent('deviceready'); 

} 

壓縮項目文件夾並將其上傳到phone-gap-build。

獲得項目構建並部署到android和windows 8.1手機(在這兩個設備上啓用了nfc)。 Phone-gap構建已經使用PhoneGap 3.7.0來構建應用程序

當我嘗試執行應用程序時,在嘗試註冊偵聽器時,Android抱怨「未找到類」。 Windows手機沒有發現任何錯誤(至少沒有看到),但沒有識別出任何提供給它的NFC卡。 在\ nfcReaderB \平臺\機器人的\ src \ COM \ chariotsolutions \ NFC \插件,我可以看到Android平臺所需的Java源文件

在手機NFC功能工作正常

的代碼可以在https://github.com/cmeegamarachchi/nfc

而且在解決這個幫助是非常讚賞

回答

1

的問題是,您使用的PhoneGap構建,但沒有正確配置插件。命令行工具用於在本地構建時安裝插件。對於PhoneGap構建,您需要在config.xml中定義插件。

<gap:plugin name="phonegap-nfc" source="npm" /> 

使用phonegap命令將項目上傳到PhoneGap Build服務器。

phonegap remote build android 

登錄到http://build.phonegap.com將該應用下載到您的手機。

代碼的更新版本可供https://github.com/don/phonegap-nfc-issue-190

有關PhoneGap的更多信息構建插件看到http://docs.build.phonegap.com/en_US/configuring_plugins.md.html#Plugins

+0

非常感謝您,先生 –

相關問題