简体   繁体   English

Android:将多个NDEF消息放在一个NFC标签中?

[英]Android: putting multiple NDEF messages in one NFC tag?

I'm trying to create an NFC tag that will trigger two separate actions: 我正在尝试创建一个NFC标签,它将触发两个单独的操作:

  • 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. 我已经使用nfc-eclipse-plugin来创建包含两个合适记录的消息,但是,当写入标记时,它总是只触发第一个动作。 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? 我知道一个NFC标签上2个NDEF消息/记录的答案--Android说你不能在标签上有两个单独的消息,只有消息中的多个记录,但是从查看包裹NDEF的TLV格式开始似乎没有什么可以阻止第二个NDEF消息出现在最后的0xFE标记字节之前?

Does anybody have any other ideas how to achieve my goal of having two separate actions on one tag? 有没有人有任何其他想法如何实现我在一个标签上有两个单独的操作的目标?

You're right, Android doesn't support two NDEF messages. 你是对的,Android不支持两条NDEF消息。 But could you have one NDEF message that contains both of your actions? 但是你有一条NDEF消息包含你的两个动作吗? 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? 并将其留给您的应用程序来解析该有效负载并确定它需要做什么?

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 . 所以只是把它包装起来:我已经将包含两个单独的NDEF 消息的标签混合在一起,而不是一个包含两个记录的消息。 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. NFC Type 2规范明确允许这样做。 However, Android silently ignores anything beyond the first message, as suspected. 但是,Android会默认忽略第一条消息之外的任何内容。

Yes. 是。 Android do not suport muliple NDEF messages. Android不支持多个NDEF消息。 It allows only one. 它只允许一个。 And you can add multiple NDEF records to a single NDEF message. 您可以将多个NDEF记录添加到单个NDEF消息中。

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});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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