Android NFC Gingerbread 到 ICS NDEF 推送不起作用
我目前正在编写一个使用 NFC 在两个设备之间发送文本的应用程序。我有两部 Nexus S 手机,一部运行的是 Ice Cream Sandwich,一部运行的是 Gingerbread 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 的标签推到前面时,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.
I'm currently writing an application which uses NFC to send text between two devices. I have two Nexus S phones, one running stock Ice Cream Sandwich and one running Gingerbread 2.3.6.
The program pushes an NDEF message, correctly formed using the example google code, to the foreground waiting to be picked up, that little code snippet is here:
/**
* 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);
}
The program works fine when I have the Gingerbread Nexus push the tag to the foreground, the ICS picks it up fine and I'm currently using NFCTagInfo to read it.
THE PROBLEM: When I have the ICS Nexus push the tag to the front the Gingerbread one doesn't seem to pick it up. I think I'm encountering a bit of a problem due to the fact that ICS uses SNEP and Gingerbread uses NPP, is there any way to force ICS to use NPP? Or if someone thinks this isn't the problem them what could it be?
NB. Ideally I would have just liked to use ICS exclusively but Google stopped putting it out over the air due to bugs and since the ICS update broke USB debugging on the Nexus I'm having to install the test applications over the internet and debugging by looking at the log on the device, not ideal, so I'm just developing for Gingerbread. This is also why I can't post up the log from the ICS but here's the Gingerbread one from when the NDEF is in the ICS foreground and Gingerbread is receiving (where it's not working):
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
And here it is from where it's in the Gingerbread foreground and ICS is receiving (this does work):
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用光束吗?我使用 nfcAdapter.setNdefPushMessageCallback() 来推送我的消息,它似乎工作正常。我已经能够将其推送到 ACR122 阅读器,并且我也可以收到该消息。我确信您已经看过开发人员教程,但我使用的示例位于底部:
http://developer.android.com/guide/topics/nfc/nfc.html
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