Class NdefMessage
java.lang.Object
com.codename1.nfc.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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvenience -- returns the first record, since most NDEF messages carry a single payload.The records carried by this message in tag order.static NdefMessageparse(byte[] raw) Parses an NDEF byte stream into a message.byte[]Serialises this message to a flat byte array using the NDEF wire format.
-
Constructor Details
-
NdefMessage
-
NdefMessage
-
-
Method Details
-
getRecords
The records carried by this message in tag order. Immutable. -
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
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
NfcExceptionwithNfcError.INVALID_NDEFwhen the input is malformed
- Throws:
NfcException
-