# Class NdefMessage

java.lang.Object
com.codename1.nfc.NdefMessage

public final class NdefMessage extends Object

An NDEF message -- the payload of an NDEF-formatted tag. A message contains one or more `NdefRecord`s in order.

Construct messages directly:

    NdefMessage msg = new NdefMessage(
        NdefRecord.createUri("https://codenameone.com"),
        NdefRecord.createText("en", "Codename One"));
    nfc.writeNdef(tag, msg);

or parse a raw byte stream via [#parse(byte[])] (the format ports use to hand a discovered tag back to your code).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NdefMessage(NdefRecord... records)`
  `NdefMessage(List<NdefRecord> records)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `NdefRecord`
  `getFirstRecord()`
  Convenience -- returns the first record, since most NDEF messages carry a single payload.
  `List<NdefRecord>`
  `getRecords()`
  The records carried by this message in tag order.
  `static NdefMessage`
  `parse(byte[] raw)`
  Parses an NDEF byte stream into a message.
  `byte[]`
  `toByteArray()`
  Serialises this message to a flat byte array using the NDEF wire format.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### NdefMessage

    public NdefMessage(NdefRecord... records)

  - ### NdefMessage

    public NdefMessage(List<NdefRecord> records)

- ## Method Details

  - ### getRecords

    public List<NdefRecord> getRecords()
    The records carried by this message in tag order. Immutable.

  - ### getFirstRecord

    public NdefRecord getFirstRecord()
    Convenience -- returns the first record, since most NDEF messages carry a single payload.

  - ### toByteArray

    public byte[] toByteArray()
    Serialises this message to a flat byte array using the NDEF wire format. Ports call this to hand a message to the OS for writing.

  - ### parse

    public static NdefMessage parse(byte[] raw) throws NfcException

    Parses an NDEF byte stream into a message. Tolerates the short-record (SR) flag and the optional id-length (IL) flag. Concatenated messages (multiple MB/ME-bracketed groups in the same stream) are not supported -- pass a single message.

    ###### Throws

    - `NfcException` with `NfcError.INVALID_NDEF` when the input is malformed
    Throws:
      `NfcException`