【问题标题】:How to Send Data Using NFC Between Android And WindowsPhone如何在 Android 和 WindowsPhone 之间使用 NFC 发送数据
【发布时间】:2014-08-24 08:10:04
【问题描述】:

我对此进行了很多搜索,但我不知道如何将文本字符串发送到 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")

【问题讨论】:

    标签: java c# android windows-phone-8 nfc


    【解决方案1】:

    在 Android 上,您想创建一个NDEFRecord,其 TNF 为 TNF_WELL_KNOWN,类型为 RTD_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) 分享;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多