简体   繁体   中英

Android NFC Gingerbread to ICS NDEF Push not working

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM