如何在Windows 8上获取NDEF消息的有效负载?
我订阅了接收类型为T(短信)的消息:
MessageType = MyProximeDevice.SubscribeForMessage("NDEF:wkt.T", MessageReceivedHandler);
在我的messageHandler上,我实现了它:
String Message = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16LE,message.Data);
但是,当我收到一条消息时,她会被展示为japaneses(或chineses?u.u)simbols。
你可以帮助我吗?
(抱歉我的英文不好:p)
答案 0 :(得分:0)
这个算法解决了我的问题:
private void MessageReceivedHandler(ProximityDevice sender, ProximityMessage message)
{
try
{
IBuffer data = message.Data;
String strHex = CryptographicBuffer.EncodeToHexString(data);
StringBuilder sb = new StringBuilder();
for (int i = 14; i <= strHex.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(strHex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
MensagemRecebida = sb.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.StackTrace);
}
}