3

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?

3 Answers 3

3

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?

2
  • Actually, I was referring to a third-party application which I can't easily change. However, for an app I'm writing myself, this might work (if "action a" is the AndroidAppRecord to launch the app)? Commented Jul 5, 2013 at 21:23
  • Ah ok. I was thinking you could parse your payload in some fashion and build the intents that you need.
    – Jon
    Commented Jul 5, 2013 at 21:25
3

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.

1
  • 1
    +1 for sharing. The result is somewhat strange, as Android returns an array of NdefMessage[] parcelable in the EXTRA_NDEF_MESSAGES.
    – ThomasRS
    Commented Jul 7, 2013 at 10:23
3

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});
1
  • can NDEF record be of similiar types.?likw two SMS or Two BT handover message types.?
    – Raulp
    Commented Dec 10, 2015 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.