写NDEF消息多次到同一个标签? [英] Write NDEF message multiple times to same tag?

查看:317
本文介绍了写NDEF消息多次到同一个标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上,只要一个NFC标签获取手机的接近,系统delievers的意图,我的应用程序,其中包含一个对象,让我来读写这个标签的NDEF消息。具体而言,我可以写这个标签经常因为我想要的,同时它还是在手机proxmity。以下的Java code给你我的意思是即时通讯pression:

On Android, as soon as an NFC tag gets in proximity of the phone, the system delievers an intent to my application that contains an objects that allows me to read and write the NDEF message of this tag. Specifically, I can write to this tag as often as I want, while it's still in proxmity of the phone. The Java code below gives you an impression of what i mean:

Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Ndef ndef = Ndef.get(tag);
ndef.writeNdefMessage(/* some NDEF data */); // first write
ndef.writeNdefMessage(/* some NDEF data */); // second write
// further writes
ndef.writeNdefMessage(/* some NDEF data */); // n-th write

我可以做同样的的的Windows Phone 8.x的的,或者我可以只进行单一的NDEF消息,写操作的标记,然后需要将它变成接近再次(移动关闭RF场,回来与标签)?

Can I do the same on Windows Phone 8.x, or can I only carry out a single NDEF-message-write operation to the tag and then need to bring it into proximity again (move off RF field and come back into with the tag)?

推荐答案

我能写标签不止一次没有它从手机中分离,并再次点击它。请参见下面的code,例如:

I'm able to write to a tag more than once without separating it from the phone and tapping it again. See following code for example:

ProximityDevice device = ProximityDevice.GetDefault();
device.SubscribeForMessage("WriteableTag", WriteableTagHandler);


private void WriteableTagHandler(ProximityDevice sender, ProximityMessage message)
{
    var message1= Encoding.Unicode.GetBytes("http://1stUrl.com");
    var message2 = Encoding.Unicode.GetBytes("http://secondUrl.com");

    sender.PublishBinaryMessage("WindowsUri:WriteTag", message1.AsBuffer(), (s, e) =>
        {
            s.StopPublishingMessage(e);
            sender.PublishBinaryMessage("WindowsUri:WriteTag", message2.AsBuffer(), (se,r)=>
            {
                se.StopPublishingMessage(r);
            });
        });              
}

编辑:

我刚检查了两个设备,而事实上,是可能的写 - 读不止一次而不必分离,并再次敲击电话。看下面的例子,其中一个设备发送5条消息,另一组接受所有的人:

I have just checked with two devices, and in fact, it is possible to write-read more than once without separating and tapping the phones again. See the example below, where one device sends 5 messages and the other receives all of them:

设备1(发件人):

ProximityDevice device = ProximityDevice.GetDefault();

device.DeviceArrived += (e) =>
    {
        for (int i = 1; i <= 5; i++)
        {
            e.PublishMessage("Windows.mySubType", "message " + i.ToString(), (s, m) =>
                {
                    s.StopPublishingMessage(m);
                });
        }
    };

2的设备(接收器):

Device 2 (receiver):

ProximityDevice device = ProximityDevice.GetDefault();

device.SubscribeForMessage("Windows.mySubType", (s, e) =>
    {
        Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(e.DataAsString);
            });
    });

这篇关于写NDEF消息多次到同一个标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆