简体   繁体   English

如何向 nfc-explorer 发送 android 光束消息

[英]How can I send android beam message to nfc-explorer

How can I send ndef message to nfc-explorer?如何向 nfc-explorer 发送 ndef 消息? I try to use source code from nfc explorer but all the time get empty ndef message.我尝试使用来自 nfc explorer 的源代码,但总是得到空的 ndef 消息。

You have a full demo implementation here , and read the official documentation.您在此处有完整的演示实现,并阅读官方文档。

To answer your question, to send a message:要回答您的问题,请发送消息:

public NdefMessage CreateNdefMessage (NfcEvent evt)
{
    DateTime time = DateTime.Now;
    var text = ("Beam me up!\n\n" + "Beam Time: " +
        time.ToString ("HH:mm:ss"));
    NdefMessage msg = new NdefMessage (
        new NdefRecord[]{ CreateMimeRecord (
            "application/com.example.android.beam",
            Encoding.UTF8.GetBytes (text)) });
        } };
    return msg;
}

public NdefRecord CreateMimeRecord (String mimeType, byte [] payload)
{
    byte [] mimeBytes = Encoding.UTF8.GetBytes (mimeType);
    NdefRecord mimeRecord = new NdefRecord (
        NdefRecord.TnfMimeMedia, mimeBytes, new byte [0], payload);
    return mimeRecord;
}

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

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