Android NFC姜饼到ICS NDEF推送无法正常工作

时间:2012-01-30 16:21:14

标签: android nfc android-4.0-ice-cream-sandwich android-2.3-gingerbread

我目前正在编写一个使用NFC在两个设备之间发送文本的应用程序。我有两部Nexus S手机,一部运行冰淇淋三明治,一部运行姜饼2.3.6。

该程序将使用示例google代码正确形成的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将标签推到前面时,Gingerbread似乎没有拿起它。我认为由于ICS使用SNEP和Gingerbread使用NPP,我遇到了一些问题,有没有办法强迫ICS使用NPP?或者,如果有人认为这不是问题,那可能是什么?

NB。理想情况下,我只是喜欢独家使用ICS,但谷歌因为错误而停止无线播放,因为ICS更新破坏了Nexus上的USB调试,我不得不通过互联网安装测试应用程序并通过查看调试登录设备,不理想,所以我只是开发姜饼。这也是为什么我不能从ICS发布日志的原因,但是这里是从NDEF处于ICS前景并且Gingerbread正在接收(它无法正常工作)的时候的Gingerbread:

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.

1 个答案:

答案 0 :(得分:0)

你正在使用光束吗?我使用nfcAdapter.setNdefPushMessageCallback()来推送我的消息,它似乎工作正常。我已经能够将其推送到ACR122阅读器,我也可以得到这个消息。我确定你已经看过开发人员的教程,但我使用的例子是在底部:

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