public final class

NdefRecord

extends Object
implements Parcelable
java.lang.Object
   ↳ android.nfc.NdefRecord

Class Overview

Represents a logical (unchunked) NDEF (NFC Data Exchange Format) record.

An NDEF record always contains:

  • 3-bit TNF (Type Name Format) field: Indicates how to interpret the type field
  • Variable length type: Describes the record format
  • Variable length ID: A unique identifier for the record
  • Variable length payload: The actual data payload

The underlying record representation may be chunked across several NDEF records when the payload is large.

This is an immutable data class.

Summary

Constants
short TNF_ABSOLUTE_URI Indicates the type field contains a value that follows the absolute-URI BNF construct defined by RFC 3986.
short TNF_EMPTY Indicates no type, id, or payload is associated with this NDEF Record.
short TNF_EXTERNAL_TYPE Indicates the type field contains a value that follows the RTD external name specification.
short TNF_MIME_MEDIA Indicates the type field contains a value that follows the media-type BNF construct defined by RFC 2046.
short TNF_UNCHANGED Indicates the payload is an intermediate or final chunk of a chunked NDEF Record.
short TNF_UNKNOWN Indicates the payload type is unknown.
short TNF_WELL_KNOWN Indicates the type field uses the RTD type name format.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<NdefRecord> CREATOR
public static final byte[] RTD_ALTERNATIVE_CARRIER RTD Alternative Carrier type.
public static final byte[] RTD_HANDOVER_CARRIER RTD Handover Carrier type.
public static final byte[] RTD_HANDOVER_REQUEST RTD Handover Request type.
public static final byte[] RTD_HANDOVER_SELECT RTD Handover Select type.
public static final byte[] RTD_SMART_POSTER RTD Smart Poster type.
public static final byte[] RTD_TEXT RTD Text type.
public static final byte[] RTD_URI RTD URI type.
Public Constructors
NdefRecord(short tnf, byte[] type, byte[] id, byte[] payload)
Construct an NDEF Record.
NdefRecord(byte[] data)
Construct an NDEF Record from raw bytes.
Public Methods
int describeContents()
byte[] getId()
Returns the variable length ID.
byte[] getPayload()
Returns the variable length payload.
short getTnf()
Returns the 3-bit TNF.
byte[] getType()
Returns the variable length Type field.
byte[] toByteArray()
Returns this entire NDEF Record as a byte array.
void writeToParcel(Parcel dest, int flags)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final short TNF_ABSOLUTE_URI

Also: Android

Indicates the type field contains a value that follows the absolute-URI BNF construct defined by RFC 3986.

Constant Value: 3 (0x00000003)

public static final short TNF_EMPTY

Also: Android

Indicates no type, id, or payload is associated with this NDEF Record.

Type, id and payload fields must all be empty to be a valid TNF_EMPTY record.

Constant Value: 0 (0x00000000)

public static final short TNF_EXTERNAL_TYPE

Also: Android

Indicates the type field contains a value that follows the RTD external name specification.

Note this TNF should not be used with RTD_TEXT or RTD_URI constants. Those are well known RTD constants, not external RTD constants.

Constant Value: 4 (0x00000004)

public static final short TNF_MIME_MEDIA

Also: Android

Indicates the type field contains a value that follows the media-type BNF construct defined by RFC 2046.

Constant Value: 2 (0x00000002)

public static final short TNF_UNCHANGED

Also: Android

Indicates the payload is an intermediate or final chunk of a chunked NDEF Record.

The payload type is specified in the first chunk, and subsequent chunks must use TNF_UNCHANGED with an empty type field. TNF_UNCHANGED must not be used in any other situation.

Constant Value: 6 (0x00000006)

public static final short TNF_UNKNOWN

Also: Android

Indicates the payload type is unknown.

This is similar to the "application/octet-stream" MIME type. The payload type is not explicitly encoded within the NDEF Message.

The type field must be empty to be a valid TNF_UNKNOWN record.

Constant Value: 5 (0x00000005)

public static final short TNF_WELL_KNOWN

Also: Android

Indicates the type field uses the RTD type name format.

Use this TNF with RTD types such as RTD_TEXT, RTD_URI.

Constant Value: 1 (0x00000001)

Fields

public static final Creator<NdefRecord> CREATOR

Also: Android

public static final byte[] RTD_ALTERNATIVE_CARRIER

Also: Android

RTD Alternative Carrier type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_HANDOVER_CARRIER

Also: Android

RTD Handover Carrier type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_HANDOVER_REQUEST

Also: Android

RTD Handover Request type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_HANDOVER_SELECT

Also: Android

RTD Handover Select type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_SMART_POSTER

Also: Android

RTD Smart Poster type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_TEXT

Also: Android

RTD Text type. For use with TNF_WELL_KNOWN.

public static final byte[] RTD_URI

Also: Android

RTD URI type. For use with TNF_WELL_KNOWN.

Public Constructors

public NdefRecord (short tnf, byte[] type, byte[] id, byte[] payload)

Also: Android

Construct an NDEF Record.

Applications should not attempt to manually chunk NDEF Records - the implementation of android.nfc will automatically chunk an NDEF Record when necessary (and only present a single logical NDEF Record to the application). So applications should not use TNF_UNCHANGED.

Parameters
tnf a 3-bit TNF constant
type byte array, containing zero to 255 bytes, must not be null
id byte array, containing zero to 255 bytes, must not be null
payload byte array, containing zero to (2 ** 32 - 1) bytes, must not be null

public NdefRecord (byte[] data)

Also: Android

Construct an NDEF Record from raw bytes.

Validation is performed to make sure the header is valid, and that the id, type and payload sizes appear to be valid.

Throws
FormatException if the data is not a valid NDEF record

Public Methods

public int describeContents ()

Also: Android

public byte[] getId ()

Also: Android

Returns the variable length ID.

public byte[] getPayload ()

Also: Android

Returns the variable length payload.

public short getTnf ()

Also: Android

Returns the 3-bit TNF.

TNF is the top-level type.

public byte[] getType ()

Also: Android

Returns the variable length Type field.

This should be used in conjunction with the TNF field to determine the payload format.

public byte[] toByteArray ()

Also: Android

Returns this entire NDEF Record as a byte array.

public void writeToParcel (Parcel dest, int flags)

Also: Android