2

我目前正在编写一个使用 NFC 在两个设备之间发送文本的应用程序。我有两部 Nexus S 手机,一部正在运行的冰淇淋三明治和一部正在运行 Gingerbread 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?或者,如果有人认为这不是问题,他们会是什么?

注意。理想情况下,我本来只想专门使用 ICS,但由于错误,Google 停止了它的无线发布,而且由于 ICS 更新破坏了 Nexus 上的 USB 调试,我不得不通过互联网安装测试应用程序并通过查看调试设备上的日志,不理想,所以我只是为 Gingerbread 开发。这也是为什么我不能从 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  

这里是它在 Gingerbread 前景中的位置,并且 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.
4

1 回答 1

0

Are you using beam? I used nfcAdapter.setNdefPushMessageCallback() to push my messages and it seems to work fine. I've been able to push this to an ACR122 reader and I can get the message as well. I'm sure you've seen the developer tutorials but the example I'm using is at the bottom:

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

于 2012-03-05T16:02:46.100 回答