簡體   English   中英

如何在Android和Windows Phone之間使用NFC發送數據

[英]How to Send Data Using NFC Between Android And WindowsPhone

我對此進行了很多搜索,但我不知道如何將文本字符串傳送到WindowsPhone設備,但是我可以將其從WindowsPhone傳送到Android。

這是我用來從WindowsPhone向Android發送消息的代碼:

ProximityDevice device = ProximityDevice.GetDefault();
// Make sure NFC is supported
if (device!= null)
{
   long Id = device.PublishMessage("Windows.MessageFromWindowsPhoneToAndroid", "Test");
}

我也在C#中找到一個代碼來接收NFC消息:

ProximityDevice device = ProximityDevice.GetDefault();
// Make sure NFC is supported
if (device!= null)
{
   long Id = device.SubscribeForMessage ("Windows.NFCBeamMSGFromAndroid", messageReceived);
}

private void messageReceived(ProximityDevice sender, ProximityMessage message)
{
   MessageBox.Show("Message Received");
   Debug.WriteLine("Received from {0}:'{1}'", sender.DeviceId, message.DataAsString);
}

我測試了針對WindowsPhone的發送NFC消息功能,並且在“標簽”應用程序中看到了消息(“ MessageFromWindowsPhoneToAndroid”)

在Android上,您要創建一個NDEFRecord與TNF_WELL_KNOWN的TNF和類型RTD_TEXT。

有效負載為字節,必須使用languageCodeLength,languageCode,text進行編碼。 用語言代​​碼“ en”編碼的有效載荷“ hello,world”將為[2、101、110、104、101、108、108、111、44、32、119、111、114、108、100]

將此NDEFRecord放入NDEFMessage並通過NFCAdapter.setNdefPushMessage(message,activity)共享;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM