public final class NdefMessage

  1. Object
  2. NdefMessage

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).

Constructors

public NdefMessage(NdefRecord... records)
public NdefMessage(List<NdefRecord> records)

Methods

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

Inherited methods

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