Share text using NFC in Windows Phone 8

I am trying to create a training application in which one user of a Windows 8 phone sends text and another user receives it. And the text is shared via NFC. But the problem is that the other user cannot get the text.

Here is the code =>

Recipient Code:

ProximityDevice device;
long subscribedMessageId;
private void receive_Click(object sender, RoutedEventArgs e)
    {
        device = ProximityDevice.GetDefault();
        if (device != null)
        {
            subscribedMessageId = device.SubscribeForMessage("Windows.SampleMessage", messageReceivedHandler);
        }
    }

    private void messageReceivedHandler(ProximityDevice sender, ProximityMessage message)
    {
        rtextbox.Text = message.DataAsString;
        device.StopSubscribingForMessage(subscribedMessageId);
    }

Sender Code:

ProximityDevice device;
long publishedMessageId;
private void send_Click(object sender, RoutedEventArgs e)
    {
        device = ProximityDevice.GetDefault();
        device.StopPublishingMessage(publishedMessageId);
        if (device != null)
        {
            publishedMessageId = device.PublishMessage("Windows.SampleMessage", textbox1.Text);
            textbox1.Text = "";
        }
    }

Both codes are present on different pages. The code is executed when the user clicks the send or receive button, respectively.

I am new to NFC, so any help would be appreciated.

+4
source share

All Articles