2012-01-30 55 views
2

我目前正在編寫一個應用程序,它使用NFC在兩個設備之間發送文本。我有兩臺Nexus S手機,一臺運行冰淇淋三明治,一臺運行薑餅2.3.6。Android NFC Gingerbread到ICS NDEF推不工作

程序推NDEF消息,使用例如谷歌代碼正確形成,到前臺等待被拾起,那個小的代碼片段是在這裏:

/** 
    * Push an NDEF to the foreground with the given text. 
    * @param message The text to be put in the message that will be pushed. 
    * 
    */ 
public void pushNDEFwithText(String text) 
{ 
    NdefRecord ndefRec = createTextRecord(text, Locale.ENGLISH, true); 
    NdefMessage message = new NdefMessage(new NdefRecord[]{ ndefRec }); 
    nfcAdapter.enableForegroundNdefPush(this, message); 
    Log.i("NDEF", "Pushed an NDEF message containing the text: "+text); 
} 

程序正常工作時,我有Gingerbread Nexus將標籤推到前臺,ICS很好地採用它,並且我正在使用NFCTagInfo來讀取它。

問題:當我有ICS Nexus將標籤推到前面時,薑餅人似乎沒有把它拿起來。由於ICS使用SNEP和Gingerbread使用NPP,我認爲我遇到了一些問題,有沒有辦法迫使ICS使用NPP?或者如果有人認爲這不是問題,他們會是什麼?

注意:理想情況下,我只是喜歡獨家使用ICS,但Google因爲缺陷而停止播出,並且因爲ICS更新打破了Nexus上的USB調試,所以我不得不通過互聯網安裝測試應用程序,並通過查看設備上的日誌,並不理想,所以我只是開發薑餅。這也是爲什麼我不能張貼從ICS的日誌,但在這裏從當NDEF在ICS前景的薑餅之一,薑餅正在接收(它不工作):

01-30 16:09:59.343: D/NFC JNI(197): Discovered P2P Target 
01-30 16:09:59.343: D/NfcService(197): LLCP Activation message 
01-30 16:09:59.394: I/NFC JNI(197): LLCP Link activated (LTO=150, MIU=128, OPTION=0x00, WKS=0x01) 
01-30 16:09:59.414: D/NdefPushClient(197): LLCP connection up and running 
01-30 16:09:59.417: D/NdefPushClient(197): no tags set, bailing 
01-30 16:10:00.160: I/NFC JNI(197): LLCP Link deactivated 
01-30 16:10:00.160: D/NfcService(197): LLCP Link Deactivated message. Restart polling loop. 
01-30 16:10:00.230: D/NFC JNI(197): Discovered P2P Target 
01-30 16:10:00.230: D/NfcService(197): LLCP Activation message 
01-30 16:10:00.304: I/NFC JNI(197): LLCP Link activated (LTO=150, MIU=128, OPTION=0x00, WKS=0x01) 
01-30 16:10:00.320: D/NdefPushClient(197): LLCP connection up and running 
01-30 16:10:00.324: D/NdefPushClient(197): no tags set, bailing 
01-30 16:10:05.621: I/NFC JNI(197): LLCP Link deactivated 

這裏,它是從它在薑餅前景和ICS正在接受的地方(這是工作):

01-30 16:18:54.058: I/ActivityManager(109): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.terminal/.TerminalActivity bnds=[5,231][115,349] } from pid 200 
01-30 16:18:54.093: I/NDEF(1314): Pushed an NDEF message containing the text: This is an example message! 
01-30 16:18:54.175: V/RenderScript_jni(200): surfaceDestroyed 
01-30 16:18:54.445: I/ActivityManager(109): Displayed com.terminal/.TerminalActivity: +360ms 
01-30 16:18:57.015: D/NfcService(197): NFC-EE routing OFF 
01-30 16:18:57.023: D/NfcService(197): NFC-C discovery ON 
01-30 16:18:57.375: D/NFC JNI(197): Discovered P2P Target 
01-30 16:18:57.375: D/NfcService(197): LLCP Activation message 
01-30 16:18:57.425: I/NFC JNI(197): LLCP Link activated (LTO=150, MIU=128, OPTION=0x00, WKS=0x01) 
01-30 16:18:57.445: D/NdefPushClient(197): LLCP connection up and running 
01-30 16:18:57.445: D/NdefPushClient(197): sending foreground 
01-30 16:18:57.449: D/NdefPushClient(197): about to create socket 
01-30 16:18:57.464: D/NdefPushClient(197): about to connect to service com.android.npp 
01-30 16:18:58.398: D/NdefPushClient(197): about to send a 44 byte message 
01-30 16:18:58.398: D/NdefPushClient(197): about to send a 44 byte packet 
01-30 16:18:58.476: D/NdefPushClient(197): about to close 
01-30 16:19:03.812: I/NFC JNI(197): LLCP Link deactivated 
01-30 16:19:03.812: D/NfcService(197): LLCP Link Deactivated message. Restart polling loop. 

回答

0

您是否在使用梁?我用nfcAdapter.setNdefPushMessageCallback()推我的消息,它似乎工作正常。我已經能夠將其推送到ACR122閱讀器,並且我也可以獲得該信息。我敢肯定,你已經看到了開發者教程,但我使用的例子是在底部:

http://developer.android.com/guide/topics/nfc/nfc.html

+0

我不認爲我有梁轉身,我已經得到「解決」它另一個ICS電話。 – Peanut 2012-03-05 18:47:12