我想写一个关于应该启动哪个应用程序的NFC标签信息,并向其添加一些文本数据。 LaunchApp工作正常,直到我想传输这个附加消息。当我添加其他消息LaunchApp
停止工作时。最好在下面的代码中解释:private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId)
如何使LaunchApp工作并将此字符串GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text
传递给标记。
public partial class MainPage : PhoneApplicationPage {
private long subscribedMessageID, publishedMessageId;
private ProximityDevice proximityDevice;
public MainPage() {
InitializeComponent();
createTagService();
}
private void createTagService() {
string appId = "{39989b95-a54a-4810-b4ee-35b33265a680}";//HomeSecurityClient Application ID
string args = "param=test";
string launchAppMessage = args + "\tWindowsPhone\t" + appId;
DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf16LE };
dataWriter.WriteString(launchAppMessage);
proximityDevice = ProximityDevice.GetDefault();
proximityDevice.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(), LaunchMesssageTransmitted);
}
private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId) {
sender.StopPublishingMessage(publishedMessageId);
/* Deployment.Current.Dispatcher.BeginInvoke(() => {
DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf8 };
dataWriter.WriteString(GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text);
sender.PublishBinaryMessage("Windows:WriteTag.NetworkData", dataWriter.DetachBuffer(), networkDataMessageTransmitted);
});*/ //IF I UNCOMMENT THIS TO TRANSMITT ADDITIONAL MESSAGE LAUNCHING APP STOPS WORKING
}
private void networkDataMessageTransmitted(ProximityDevice sender, long publishedMessageId) {
sender.StopPublishingMessage(publishedMessageId);
Deployment.Current.Dispatcher.BeginInvoke(() => {
MessageBox.Show("The data is written");
});
sender.StopPublishingMessage(publishedMessageId);
}
}
答案 0 :(得分:0)
您不能在一个标签上写两条单独的NDEF消息。最后一条消息将始终覆盖以前的任何消息。但是,您可以做的是在一条NDEF消息中将两条记录(LaunchApp记录和您的自定义记录)写入标记。为此,您可以将PublishBinaryMessage()
方法与消息类型“NDEF:WriteTag”一起使用。这样您就可以将格式正确的(!)NDEF消息传递给标记。创建格式正确的NDEF消息的方法是使用http://ndef.mopius.com/中的免费NFC库。