Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/nfc/NdefRecord#constants) \| [Inherited Constants](https://developer.android.com/reference/android/nfc/NdefRecord#inhconstants) \| [Fields](https://developer.android.com/reference/android/nfc/NdefRecord#lfields) \| [Ctors](https://developer.android.com/reference/android/nfc/NdefRecord#pubctors) \| [Methods](https://developer.android.com/reference/android/nfc/NdefRecord#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/nfc/NdefRecord#inhmethods)

# NdefRecord

*** ** * ** ***

` public final class NdefRecord `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.nfc.NdefRecord |

<br />

*** ** * ** ***

Represents an immutable NDEF Record.

NDEF (NFC Data Exchange Format) is a light-weight binary format, used to encapsulate typed data. It is specified by the NFC Forum, for transmission and storage with NFC, however it is transport agnostic.

NDEF defines messages and records. An NDEF Record contains typed data, such as MIME-type media, a URI, or a custom application payload. An NDEF Message is a container for one or more NDEF Records.

This class represents logical (complete) NDEF Records, and can not be used to represent chunked (partial) NDEF Records. However `https://developer.android.com/reference/android/nfc/NdefMessage#NdefMessage(byte[])` can be used to parse a message containing chunked records, and will return a message with unchunked (complete) records.

A logical NDEF Record always contains a 3-bit TNF (Type Name Field) that provides high level typing for the rest of the record. The remaining fields are variable length and not always present:

- *type*: detailed typing for the payload
- *id*: identifier meta-data, not commonly used
- *payload*: the actual payload

Helpers such as `https://developer.android.com/reference/android/nfc/NdefRecord#createUri(android.net.Uri)`, `https://developer.android.com/reference/android/nfc/NdefRecord#createMime(java.lang.String,%20byte[])` and `https://developer.android.com/reference/android/nfc/NdefRecord#createExternal(java.lang.String,%20java.lang.String,%20byte[])` are included to create well-formatted NDEF Records with correctly set tnf, type, id and payload fields, please use these helpers whenever possible.

Use the constructor `https://developer.android.com/reference/android/nfc/NdefRecord#NdefRecord(short,%20byte[],%20byte[],%20byte[])` if you know what you are doing and what to set the fields individually. Only basic validation is performed with this constructor, so it is possible to create records that do not confirm to the strict NFC Forum specifications.

The binary representation of an NDEF Record includes additional flags to indicate location with an NDEF message, provide support for chunking of NDEF records, and to pack optional fields. This class does not expose those details. To write an NDEF Record as binary you must first put it into an `https://developer.android.com/reference/android/nfc/NdefMessage`, then call `https://developer.android.com/reference/android/nfc/NdefMessage#toByteArray()`.

`https://developer.android.com/reference/android/nfc/NdefMessage` and `https://developer.android.com/reference/android/nfc/NdefRecord` implementations are always available, even on Android devices that do not have NFC hardware.

`https://developer.android.com/reference/android/nfc/NdefRecord`s are intended to be immutable (and thread-safe), however they may contain mutable fields. So take care not to modify mutable fields passed into constructors, or modify mutable fields obtained by getter methods, unless such modification is explicitly marked as safe.
**See also:**

- `https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_NDEF_DISCOVERED`
- `https://developer.android.com/reference/android/nfc/NdefMessage`

## Summary

| ### Constants ||
|---|---|
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_ABSOLUTE_URI` Indicates the type field contains an absolute-URI BNF construct defined by RFC 3986. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_EMPTY` Indicates the record is empty. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_EXTERNAL_TYPE` Indicates the type field contains an external type name. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_MIME_MEDIA` Indicates the type field contains a media-type BNF construct, defined by RFC 2046. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_UNCHANGED` Indicates the payload is an intermediate or final chunk of a chunked NDEF Record. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_UNKNOWN` Indicates the payload type is unknown. |
| `short` | `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` Indicates the type field contains a well-known RTD type name. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/nfc/NdefRecord>` | `https://developer.android.com/reference/android/nfc/NdefRecord#CREATOR` <br /> |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_ALTERNATIVE_CARRIER` RTD Alternative Carrier type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_HANDOVER_CARRIER` RTD Handover Carrier type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_HANDOVER_REQUEST` RTD Handover Request type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_HANDOVER_SELECT` RTD Handover Select type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_SMART_POSTER` RTD Smart Poster type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_TEXT` RTD Text type. |
| ` public static final byte[]` | `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI` RTD URI type. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/nfc/NdefRecord#NdefRecord(byte[])(byte[] data) ` *This constructor is deprecated. use `https://developer.android.com/reference/android/nfc/NdefMessage#NdefMessage(byte[])` instead.* |
| ` https://developer.android.com/reference/android/nfc/NdefRecord#NdefRecord(short,%20byte[],%20byte[],%20byte[])(short tnf, byte[] type, byte[] id, byte[] payload) ` Construct an NDEF Record from its component fields. |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createApplicationRecord(java.lang.String)(https://developer.android.com/reference/java/lang/String packageName) ` Create a new Android Application Record (AAR). |
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createExternal(java.lang.String,%20java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String domain, https://developer.android.com/reference/java/lang/String type, byte[] data) ` Create a new NDEF Record containing external (application-specific) data. |
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createMime(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String mimeType, byte[] mimeData) ` Create a new NDEF Record containing MIME data. |
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createTextRecord(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String languageCode, https://developer.android.com/reference/java/lang/String text) ` Create a new NDEF record containing UTF-8 text data. |
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createUri(android.net.Uri)(https://developer.android.com/reference/android/net/Uri uri) ` Create a new NDEF Record containing a URI. |
| ` static https://developer.android.com/reference/android/nfc/NdefRecord` | ` https://developer.android.com/reference/android/nfc/NdefRecord#createUri(java.lang.String)(https://developer.android.com/reference/java/lang/String uriString) ` Create a new NDEF Record containing a URI. |
| ` int` | ` https://developer.android.com/reference/android/nfc/NdefRecord#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` boolean` | ` https://developer.android.com/reference/android/nfc/NdefRecord#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Returns true if the specified NDEF Record contains identical tnf, type, id and payload fields. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/NdefRecord#getId()() ` Returns the variable length ID. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/NdefRecord#getPayload()() ` Returns the variable length payload. |
| ` short` | ` https://developer.android.com/reference/android/nfc/NdefRecord#getTnf()() ` Returns the 3-bit TNF. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/NdefRecord#getType()() ` Returns the variable length Type field. |
| ` int` | ` https://developer.android.com/reference/android/nfc/NdefRecord#hashCode()() ` Returns a hash code value for the object. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/NdefRecord#toByteArray()() ` *This method was deprecated in API level 16. use `https://developer.android.com/reference/android/nfc/NdefMessage#toByteArray()` instead* |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/nfc/NdefRecord#toMimeType()() ` Map this record to a MIME type, or return null if it cannot be mapped. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/nfc/NdefRecord#toString()() ` Returns a string representation of the object. |
| ` https://developer.android.com/reference/android/net/Uri` | ` https://developer.android.com/reference/android/nfc/NdefRecord#toUri()() ` Map this record to a URI, or return null if it cannot be mapped. |
| ` void` | ` https://developer.android.com/reference/android/nfc/NdefRecord#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) ` Flatten this object in to a Parcel. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Constants

### TNF_ABSOLUTE_URI

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_ABSOLUTE_URI
```

Indicates the type field contains an absolute-URI BNF construct defined by RFC 3986.

When creating new records prefer `https://developer.android.com/reference/android/nfc/NdefRecord#createUri(android.net.Uri)`, since it offers more compact URI encoding (#RTD_URI allows compression of common URI prefixes).

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#createUri(android.net.Uri)`

Constant Value: 3 (0x00000003)

### TNF_EMPTY

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_EMPTY
```

Indicates the record is empty.

Type, id and payload fields are empty in a TNF_EMPTY record.

<br />

Constant Value: 0 (0x00000000)

### TNF_EXTERNAL_TYPE

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_EXTERNAL_TYPE
```

Indicates the type field contains an external type name.

Used to encode custom payloads. When creating new records use the helper `https://developer.android.com/reference/android/nfc/NdefRecord#createExternal(java.lang.String,%20java.lang.String,%20byte[])`.

The external-type RTD format is specified in NFCForum-TS-RTD_1.0.

<br />

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

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#createExternal(java.lang.String,%20java.lang.String,%20byte[])`

Constant Value: 4 (0x00000004)

### TNF_MIME_MEDIA

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_MIME_MEDIA
```

Indicates the type field contains a media-type BNF construct, defined by RFC 2046.

Use this with MIME type names such as "image/jpeg", or using the helper `https://developer.android.com/reference/android/nfc/NdefRecord#createMime(java.lang.String,%20byte[])`.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#createMime(java.lang.String,%20byte[])`

Constant Value: 2 (0x00000002)

### TNF_UNCHANGED

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_UNCHANGED
```

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

TNF_UNCHANGED can not be used with this class since all `https://developer.android.com/reference/android/nfc/NdefRecord`s are already unchunked, however they may appear in the binary format.

<br />

Constant Value: 6 (0x00000006)

### TNF_UNKNOWN

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_UNKNOWN
```

Indicates the payload type is unknown.

NFC Forum explains this should be treated similarly to the "application/octet-stream" MIME type. The payload type is not explicitly encoded within the record.

The type field is empty in an TNF_UNKNOWN record.

<br />

Constant Value: 5 (0x00000005)

### TNF_WELL_KNOWN

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final short TNF_WELL_KNOWN
```

Indicates the type field contains a well-known RTD type name.

Use this tnf with RTD types such as `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_TEXT`, `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI`.

The RTD type name format is specified in NFCForum-TS-RTD_1.0.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI`
- `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_TEXT`
- `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_SMART_POSTER`
- `https://developer.android.com/reference/android/nfc/NdefRecord#createUri(android.net.Uri)`

Constant Value: 1 (0x00000001)

## Fields

### CREATOR

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<NdefRecord> CREATOR
```

<br />

<br />

### RTD_ALTERNATIVE_CARRIER

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_ALTERNATIVE_CARRIER
```

RTD Alternative Carrier type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_HANDOVER_CARRIER

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_HANDOVER_CARRIER
```

RTD Handover Carrier type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_HANDOVER_REQUEST

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_HANDOVER_REQUEST
```

RTD Handover Request type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_HANDOVER_SELECT

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_HANDOVER_SELECT
```

RTD Handover Select type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_SMART_POSTER

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_SMART_POSTER
```

RTD Smart Poster type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_TEXT

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_TEXT
```

RTD Text type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

### RTD_URI

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final byte[] RTD_URI
```

RTD URI type. For use with TNF_WELL_KNOWN.

<br />

**See also:**

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN`

## Public constructors

### NdefRecord

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public NdefRecord (byte[] data)
```

<br />

**This constructor is deprecated.**   

use `https://developer.android.com/reference/android/nfc/NdefMessage#NdefMessage(byte[])` instead.

Construct an NDEF Record from raw bytes.

This method is deprecated, use `https://developer.android.com/reference/android/nfc/NdefMessage#NdefMessage(byte[])` instead. This is because it does not make sense to parse a record: the NDEF binary format is only defined for a message, and the record flags MB and ME do not make sense outside of the context of an entire message.

This implementation will attempt to parse a single record by ignoring the MB and ME flags, and otherwise following the rules of `https://developer.android.com/reference/android/nfc/NdefMessage#NdefMessage(byte[])`.

<br />

<br />

| Parameters ||
|---|---|
| `data` | `byte`: raw bytes to parse <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/nfc/FormatException` | if the data cannot be parsed into a valid record |

### NdefRecord

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Construct an NDEF Record from its component fields.

Recommend to use helpers such as {#createUri} or {`https://developer.android.com/reference/android/nfc/NdefRecord#createExternal(java.lang.String,%20java.lang.String,%20byte[])` where possible, since they perform stricter validation that the record is correctly formatted as per NDEF specifications. However if you know what you are doing then this constructor offers the most flexibility.

An `https://developer.android.com/reference/android/nfc/NdefRecord` represents a logical (complete) record, and cannot represent NDEF Record chunks.

Basic validation of the tnf, type, id and payload is performed as per the following rules:

- The tnf paramter must be a 3-bit value.
- Records with a tnf of `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_EMPTY` cannot have a type, id or payload.
- Records with a tnf of `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_UNKNOWN` or 0x07 cannot have a type.
- Records with a tnf of `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_UNCHANGED` are not allowed since this class only represents complete (unchunked) records.

This minimal validation is specified by NFCForum-TS-NDEF_1.0 section 3.2.6 (Type Name Format).

If any of the above validation steps fail then `https://developer.android.com/reference/java/lang/IllegalArgumentException` is thrown.

Deep inspection of the type, id and payload fields is not performed, so it is possible to create NDEF Records that conform to section 3.2.6 but fail other more strict NDEF specification requirements. For example, the payload may be invalid given the tnf and type.

To omit a type, id or payload field, set the parameter to an empty byte array or null.

<br />

| Parameters ||
|---|---|
| `tnf` | `short`: a 3-bit TNF constant <br /> |
| `type` | `byte`: byte array, containing zero to 255 bytes, or null <br /> |
| `id` | `byte`: byte array, containing zero to 255 bytes, or null <br /> |
| `payload` | `byte`: byte array, containing zero to (2 \*\* 32 - 1) bytes, or null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if a valid record cannot be created |

## Public methods

### createApplicationRecord

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createApplicationRecord (String packageName)
```

Create a new Android Application Record (AAR).

This record indicates to other Android devices the package that should be used to handle the entire NDEF message. You can embed this record anywhere into your message to ensure that the intended package receives the message.

When an Android device dispatches an `https://developer.android.com/reference/android/nfc/NdefMessage` containing one or more Android application records, the applications contained in those records will be the preferred target for the `https://developer.android.com/reference/android/nfc/NfcAdapter#ACTION_NDEF_DISCOVERED` intent, in the order in which they appear in the message. This dispatch behavior was first added to Android in Ice Cream Sandwich.

If none of the applications have a are installed on the device, a Market link will be opened to the first application.

Note that Android application records do not overrule applications that have called `https://developer.android.com/reference/android/nfc/NfcAdapter#enableForegroundDispatch(android.app.Activity,%20android.app.PendingIntent,%20android.content.IntentFilter[],%20java.lang.String[][])`.

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: Android package name <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | Android application NDEF record <br /> |

### createExternal

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createExternal (String domain, 
                String type, 
                byte[] data)
```

Create a new NDEF Record containing external (application-specific) data.

Use this method to encode application specific data into an NDEF Record. The data is typed by a domain name (usually your Android package name) and a domain-specific type. This data is packaged into a "NFC Forum External Type" NDEF Record.

NFC Forum requires that the domain and type used in an external record are treated as case insensitive, however Android intent filtering is always case sensitive. So this method will force the domain and type to lower-case before creating the NDEF Record.

The unchecked exception `https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown if the domain and type have serious problems, for example if either field is empty, so always catch this exception if you are passing user-generated data into this method.

There are no such restrictions on the payload data.

For efficiency, This method might not make an internal copy of the data byte array, so take care not to modify the data byte array while still using the returned NdefRecord. Reference specification: NFCForum-TS-RTD_1.0

<br />

| Parameters ||
|---|---|
| `domain` | `String`: domain-name of issuing organization <br /> |
| `type` | `String`: domain-specific type of data <br /> |
| `data` | `byte`: payload as bytes <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if either domain or type are empty or invalid |

### createMime

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createMime (String mimeType, 
                byte[] mimeData)
```

Create a new NDEF Record containing MIME data.

Use this method to encode MIME-typed data into an NDEF Record, such as "text/plain", or "image/jpeg".

The mimeType parameter will be normalized with `https://developer.android.com/reference/android/content/Intent#normalizeMimeType(java.lang.String)` to follow Android best practices for intent filtering, for example to force lower-case. However the unchecked exception `https://developer.android.com/reference/java/lang/IllegalArgumentException` may be thrown if the mimeType parameter has serious problems, for example if it is empty, so always catch this exception if you are passing user-generated data into this method.

For efficiency, This method might not make an internal copy of the mimeData byte array, so take care not to modify the mimeData byte array while still using the returned NdefRecord.

<br />

| Parameters ||
|---|---|
| `mimeType` | `String`: a valid MIME type <br /> |
| `mimeData` | `byte`: MIME data as bytes <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | an NDEF Record containing the MIME-typed data <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the mimeType is empty or invalid |

### createTextRecord

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createTextRecord (String languageCode, 
                String text)
```

Create a new NDEF record containing UTF-8 text data.

The caller can either specify the language code for the provided text, or otherwise the language code corresponding to the current default locale will be used. Reference specification: NFCForum-TS-RTD_Text_1.0

<br />

| Parameters ||
|---|---|
| `languageCode` | `String`: The languageCode for the record. If locale is empty or null, the language code of the current default locale will be used. <br /> |
| `text` | `String`: The text to be encoded in the record. Will be represented in UTF-8 format. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if text is null |

### createUri

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createUri (Uri uri)
```

Create a new NDEF Record containing a URI.

Use this method to encode a URI (or URL) into an NDEF Record.

Uses the well known URI type representation: `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` and `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI`. This is the most efficient encoding of a URI into NDEF.

The uri parameter will be normalized with `https://developer.android.com/reference/android/net/Uri#normalizeScheme()` to set the scheme to lower case to follow Android best practices for intent filtering. However the unchecked exception `https://developer.android.com/reference/java/lang/IllegalArgumentException` may be thrown if the uri parameter has serious problems, for example if it is empty, so always catch this exception if you are passing user-generated data into this method.

Reference specification: NFCForum-TS-RTD_URI_1.0

<br />

| Parameters ||
|---|---|
| `uri` | `Uri`: URI to encode. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | an NDEF Record containing the URI <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the uri is empty or invalid |

### createUri

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static NdefRecord createUri (String uriString)
```

Create a new NDEF Record containing a URI.

Use this method to encode a URI (or URL) into an NDEF Record.

Uses the well known URI type representation: `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` and `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI`. This is the most efficient encoding of a URI into NDEF.

The uriString parameter will be normalized with `https://developer.android.com/reference/android/net/Uri#normalizeScheme()` to set the scheme to lower case to follow Android best practices for intent filtering. However the unchecked exception `https://developer.android.com/reference/java/lang/IllegalArgumentException` may be thrown if the uriString parameter has serious problems, for example if it is empty, so always catch this exception if you are passing user-generated data into this method.

Reference specification: NFCForum-TS-RTD_URI_1.0

<br />

| Parameters ||
|---|---|
| `uriString` | `String`: string URI to encode. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/NdefRecord` | an NDEF Record containing the URI <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the uriString is empty or invalid |

### describeContents

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### equals

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object obj)
```

Returns true if the specified NDEF Record contains identical tnf, type, id and payload fields.

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this object is the same as the obj argument; `false` otherwise. <br /> |

### getId

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] getId ()
```

Returns the variable length ID.

Returns an empty byte array if this record does not have an id field.

<br />

| Returns ||
|---|---|
| `byte[]` | <br /> |

### getPayload

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] getPayload ()
```

Returns the variable length payload.

Returns an empty byte array if this record does not have a payload field.

<br />

| Returns ||
|---|---|
| `byte[]` | <br /> |

### getTnf

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public short getTnf ()
```

Returns the 3-bit TNF.

TNF is the top-level type.

<br />

| Returns ||
|---|---|
| `short` | <br /> |

### getType

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] getType ()
```

Returns the variable length Type field.

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

Returns an empty byte array if this record does not have a type field.

<br />

| Returns ||
|---|---|
| `byte[]` | <br /> |

### hashCode

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by `https://developer.android.com/reference/java/util/HashMap`.

The general contract of `hashCode` is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the `hashCode` method must consistently return the same integer, provided no information used in `equals` comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce the same integer result.
- It is *not* required that if two objects are unequal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

| Returns ||
|---|---|
| `int` | a hash code value for this object. <br /> |

### toByteArray

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] toByteArray ()
```

<br />

**This method was deprecated in API level 16.**   

use `https://developer.android.com/reference/android/nfc/NdefMessage#toByteArray()` instead

Return this NDEF Record as a byte array.

This method is deprecated, use `https://developer.android.com/reference/android/nfc/NdefMessage#toByteArray()` instead. This is because the NDEF binary format is not defined for a record outside of the context of a message: the MB and ME flags cannot be set without knowing the location inside a message.

This implementation will attempt to serialize a single record by always setting the MB and ME flags (in other words, assume this is a single-record NDEF Message).

<br />

<br />

| Returns ||
|---|---|
| `byte[]` | <br /> |

### toMimeType

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toMimeType ()
```

Map this record to a MIME type, or return null if it cannot be mapped.

Currently this method considers all `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_MIME_MEDIA` records to be MIME records, as well as some `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` records such as `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_TEXT`. If this is a MIME record then the MIME type as string is returned, otherwise null is returned.

This method does not perform validation that the MIME type is actually valid. It always attempts to return a string containing the type if this is a MIME record.

The returned MIME type will by normalized to lower-case using `https://developer.android.com/reference/android/content/Intent#normalizeMimeType(java.lang.String)`.

The MIME payload can be obtained using `https://developer.android.com/reference/android/nfc/NdefRecord#getPayload()`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | MIME type as a string, or null if this is not a MIME record <br /> |

### toString

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### toUri

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Uri toUri ()
```

Map this record to a URI, or return null if it cannot be mapped.

Currently this method considers the following to be URI records:

- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_ABSOLUTE_URI` records.
- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` with a type of `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_URI`.
- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_WELL_KNOWN` with a type of `https://developer.android.com/reference/android/nfc/NdefRecord#RTD_SMART_POSTER` and containing a URI record in the NDEF message nested in the payload.
- `https://developer.android.com/reference/android/nfc/NdefRecord#TNF_EXTERNAL_TYPE` records.

If this is not a URI record by the above rules, then null is returned.

This method does not perform validation that the URI is actually valid: it always attempts to create and return a URI if this record appears to be a URI record by the above rules.

The returned URI will be normalized to have a lower case scheme using `https://developer.android.com/reference/android/net/Uri#normalizeScheme()`.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/Uri` | URI, or null if this is not a URI record <br /> |

### writeToParcel

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `dest` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |