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 NdefRecords 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 Details

  • 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
      Throws:
      NfcException