Samsung Electronics logo

Exchanging NDEF Data with Peers



Learning how to exchange NDEF data with peer devices is a basic NFC management skill:

  1. To receive NDEF messages from a peer device, use the setReceiveNDEFListener() method of the NFCPeer interface.

    The setReceiveNDEFListener() method registers the NDEFMessageReadCallback listener interface, which is invoked when an NDEF message from a peer device is read.

    /* NDEFMessageReadCallback listener */
    function readMessage(message) 
    {
       console.log("Record Count is " + message.recordCount);
    }
    
    /* Set a listener to receive an NDEF message */
    Peer.setReceiveNDEFListener(readMessage);
  2. To send an NDEF message to an NFC peer, use the sendNDEF() method:

    var newMessage = new webapis.NDEFMessage(); 	
    	
    Peer.sendNDEF(newMessage, writeCallback);