locked
How to convert an object into NDEF data format(as a bytes[] ) to exchange data using NFC?

    Question

  • Hi Everyone,

    I am trying to exchange one object which contains name and address details using NFC(proximity). for publishing and subscribing, I am using windows.urn format and it is working fine but, I want to convert the object into NDEF format and exchange the data (please don't ask the reason for format change required) . my code snippet for the above is as follows.

    // for publishing 
                    if (publishedMessageId != -1 && myproximityDevice != null)
                    {
                        myproximityDevice.StopPublishingMessage(publishedMessageId);
                        publishedMessageId = -1;
                    }
                    MemoryStream stream = new MemoryStream();
    
                    var serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(details));
                    serializer.WriteObject(stream, objSendingDetails);
    
                    byte[] array = new byte[stream.Length];
    
                    stream.Position = 0;
                    stream.Read(array, 0, (int)stream.Length);
                    DataWriter dataWriter = new DataWriter();
                    dataWriter.ByteOrder = ByteOrder.BigEndian;
                    dataWriter.WriteBytes(array);
                                    if (myproximityDevice == null)
                        return;
                    publishedMessageId = myproximityDevice.PublishBinaryMessage("Windows.urn:Details", dataWriter.DetachBuffer(), ProximityDevice_MessageTransmittedHandler);
    // fro subscribing 
    
     if (myproximityDevice == null)
                        return;
                    //App.serclient.showToastNotifcation("insubscribeprofile");
    
                    subscribedMessageId = myproximityDevice.SubscribeForMessage("Windows.urn:Details", async (ProximityDevice sender, ProximityMessage message) =>
                      {
    
                          await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                          {
    }
    }



    Friday, January 23, 2015 9:58 AM

Answers

All replies

  • Hi Badri,

    As I know, NDEF format contains some header: http://developer.nokia.com/community/wiki/Understanding_NFC_Data_Exchange_Format_(NDEF)_messages

    Did you have those headers included in your message? I did not see those things from your code snippet.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, January 26, 2015 5:22 AM
    Moderator
  • Hi Jamles,

    Thanks for your reply. I didn't include any headers in the message as windows.urn format doesn't requires those (as I know).

    any process or documentation to include headers and convert an object into NDEF format is greatly appreciated.

    Thanks & Regards,

    Badri 

    Tuesday, January 27, 2015 5:42 AM
  • Hi Badri,

    There is one sample on the link I provided to you, could you take a look.

    There also some explanation on github: http://mopius.github.io/ndef-nfc/ reference here if you need. 

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 28, 2015 7:21 AM
    Moderator