简体   繁体   English

如何在Android和Windows Phone之间使用NFC发送数据

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

i searched a lot about this but i don't know how can I beam a Text String to WindowsPhone Device but i can do it From WindowsPhone To Android. 我对此进行了很多搜索,但我不知道如何将文本字符串传送到WindowsPhone设备,但是我可以将其从WindowsPhone传送到Android。

here is the code I'm using to Send Message From WindowsPhone to Android : 这是我用来从WindowsPhone向Android发送消息的代码:

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

also i found a code in C# to receive a NFC Message : 我也在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);
}

i test the send NFC message Function For WindowsPhone and i see the message ("MessageFromWindowsPhoneToAndroid") in Tags Application. 我测试了针对WindowsPhone的发送NFC消息功能,并且在“标签”应用程序中看到了消息(“ MessageFromWindowsPhoneToAndroid”)

On Android, you want to create a NDEFRecord with a TNF of TNF_WELL_KNOWN and Type RTD_TEXT. 在Android上,您要创建一个NDEFRecord与TNF_WELL_KNOWN的TNF和类型RTD_TEXT。

The payload is bytes and must be encoded with languageCodeLength, languageCode, text. 有效负载为字节,必须使用languageCodeLength,languageCode,text进行编码。 The payload "hello, world" encoded with the language code "en" would be [2, 101, 110, 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100] 用语言代​​码“ en”编码的有效载荷“ hello,world”将为[2、101、110、104、101、108、108、111、44、32、119、111、114、108、100]

Put this NDEFRecord into a NDEFMessage and share via NFCAdapter.setNdefPushMessage(message, activity) ; 将此NDEFRecord放入NDEFMessage并通过NFCAdapter.setNdefPushMessage(message,activity)共享;

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

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