Samsung Electronics logo

Exchanging NDEF Data with Tags

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

  1. To read data from an NFC tag, use the readNDEF() method of the NFCTag interface.

    The readNDEF() method registers the NDEFMessageReadCallback listener interface, which is invoked when an NDEF message is read.

    /* NDEFMessageReadCallback listener */
    function readMessage(message) 
       console.log("Record Count is " + message.recordCount);
    /* Check whether the NFC tag supports NDEF format */
    if (Tag.isSupportedNDEF) 
       /* Read NDEF data */
  2. To write data on an NFC tag, use the writeNDEF() method:

    var newMessage = new webapis.NDEFMessage(); 	
    Tag.writeNDEF(newMessage, writeCallback);

    You can use the transceive() method to transfer raw data, as a byte array, to an NFC tag without knowing the underlying details of the tag.