Question

I'm trying to create an NFC tag that will trigger two separate actions:

  • open a Bluetooth connection
  • launching an app (or going to the play store)

I've used nfc-eclipse-plugin to create a message containing two suitable records, however, when written to a tag, it always only triggers the first action. Both work individually, but the second one is always ignored.

I know that the answer to 2 NDEF mesages/records on one NFC tag - Android says that you can't have two separate messages on a tag, only multiple records within a message, but from looking at the TLV format which wraps NDEF, there seems to be nothing to actually prevent a second NDEF message from appearing before the final 0xFE marker byte?

Does anybody have any other ideas how to achieve my goal of having two separate actions on one tag?

Was it helpful?

Solution

You're right, Android doesn't support two NDEF messages. But could you have one NDEF message that contains both of your actions? What I mean is, could your payload be something like:

"action a,action b" 

and leave it up to your application to parse that payload and determine what it needs to do?

OTHER TIPS

So just to wrap this up: I've hacked together a tag containing two separate NDEF messages as opposed to one message with two records. At the byte level directly on the tag, this looks as follows:

0x03 <length1> <message1> ... 0x03 <length2> <message2> ... 0xFE

The NFC Type 2 specification explicitly allows this. However, Android silently ignores anything beyond the first message, as suspected.

Yes. Android do not suport muliple NDEF messages. It allows only one. And you can add multiple NDEF records to a single NDEF message.

NdefRecord text1 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
                                  message1.getBytes(),
                                  new byte[]{},
                                  message1.getBytes());
NdefRecord text2 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
                                  message2.getBytes(),
                                  new byte[]{},
                                  message2.getBytes());
NdefMessage mNdefMessage = new NdefMessage(new NdefRecord[]{text1,text2});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top