Proximity Device API - NDEF发布的参数异常

时间:2016-07-08 20:24:48

标签: c# uwp nfc ndef

我正在尝试使用Windows Proximity Device API编写二进制数据。

我可以发现NFC标签,我可以从TAG中读取NDEF消息,这些消息是在Android手机上写的。

但是当我尝试设置PublishBinaryMessage时,我总是会在使用此messageTypes时收到ArgumentException(Value不在预期范围内): “NDEF”,“WriteableTag”或https://msdn.microsoft.com/en-us/library/windows/apps/hh701129.aspx中描述的任何其他内容 除“Windows.someSubtype”。但在这种情况下,我的TAG没有写入。

我用“NDEF.someSubtype”获取ArgumentException,但是消息是“Message”参数不正确。这个ProximityDevice不支持传入的messageType:NDEF.someSubtype“

代码:

//Does not work - Argument Exception - "Value does not fall within the expected range"
messageID = proximityDevice.PublishBinaryMessage("NDEF", Encoding.UTF8.GetBytes("lorem ipsum").AsBuffer(), MessageTransmittedHandler);

//Does not work - Argument Exception - "The parameter is incorrect"
messageID = proximityDevice.PublishBinaryMessage("NDEF.something", Encoding.UTF8.GetBytes("lorem ipsum").AsBuffer(), MessageTransmittedHandler);

//No Exception, but never writes on device.
messageID = proximityDevice.PublishBinaryMessage("Windows.something", Encoding.UTF8.GetBytes("lorem ipsum").AsBuffer(), MessageTransmittedHandler);

1 个答案:

答案 0 :(得分:1)

输入缓冲区错误。对于NDEF消息,API文档说:

  

邮件内容格式正确的NDEF记录

因此,使用Andijac(https://github.com/andijakl/ndef-nfc)中的ndef-nfc库,二进制消息已正确发布。