我目前正在编写一个应用程序,该应用程序使用NFC在两台设备之间发送文本。我有两部Nexus S手机,一部正在运行冰淇淋三明治,一部在运行姜饼2.3.6。
该程序将使用示例谷歌代码正确形成的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,但谷歌由于错误而停止了它的发布。由于ICS更新破坏了Nexus上的USB调试,我不得不在互联网上安装测试应用程序,并通过查看设备上的日志进行调试,这并不理想,所以我只是在为Gingerbread开发。这也是为什么我不能从ICS发布日志,但这是当NDEF在ICS前台并且Gingerbread正在接收(它不工作的地方)时的Gingerbead日志:
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.
您在使用beam吗?我使用了nfcAdapter.setNdefPushMessageCallback()来推送我的消息,它似乎工作得很好。我已经能够把这个推送给ACR122阅读器,我也可以得到消息。我相信你已经看过开发人员教程,但我使用的例子在底部:
http://developer.android.com/guide/topics/nfc/nfc.html