【问题标题】:Android NFC Gingerbread to ICS NDEF Push not workingAndroid NFC Gingerbread 到 ICS NDEF 推送不起作用
【发布时间】:2012-01-30 16:21:14
【问题描述】:

我目前正在编写一个使用 NFC 在两个设备之间发送文本的应用程序。我有两部 Nexus S 手机,一部正在运行 Ice Cream Sandwich,另一部正在运行 Gingerbread 2.3.6。

程序将使用示例 google 代码正确形成的 NDEF 消息推送到等待被拾取的前台,小代码 sn-p 在这里:

/**
  * 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.

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我不认为我已经转向 Beam,我已经通过购买另一部 ICS 手机“解决”了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多