Added in [API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/nfc/tech/MifareUltralight#constants) \| [Methods](https://developer.android.com/reference/android/nfc/tech/MifareUltralight#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/nfc/tech/MifareUltralight#inhmethods)

# MifareUltralight

*** ** * ** ***

` public final class MifareUltralight `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/nfc/tech/TagTechnology `

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

<br />

*** ** * ** ***

Provides access to MIFARE Ultralight properties and I/O operations on a `https://developer.android.com/reference/android/nfc/Tag`.

Acquire a `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` object using `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#get(android.nfc.Tag)`.

MIFARE Ultralight compatible tags have 4 byte pages `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#PAGE_SIZE`. The primary operations on an Ultralight tag are `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#readPages(int)` and `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#writePage(int,%20byte[])`.

The original MIFARE Ultralight consists of a 64 byte EEPROM. The first 4 pages are for the OTP area, manufacturer data, and locking bits. They are readable and some bits are writable. The final 12 pages are the user read/write area. For more information see the NXP data sheet MF0ICU1.

The MIFARE Ultralight C consists of a 192 byte EEPROM. The first 4 pages are for OTP, manufacturer data, and locking bits. The next 36 pages are the user read/write area. The next 4 pages are additional locking bits, counters and authentication configuration and are readable. The final 4 pages are for the authentication key and are not readable. For more information see the NXP data sheet MF0ICU2.

Implementation of this class on a Android NFC device is optional. If it is not implemented, then `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` will never be enumerated in `https://developer.android.com/reference/android/nfc/Tag#getTechList()`. If it is enumerated, then all `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` I/O operations will be supported. In either case, `https://developer.android.com/reference/android/nfc/tech/NfcA` will also be enumerated on the tag, because all MIFARE Ultralight tags are also `https://developer.android.com/reference/android/nfc/tech/NfcA` tags.

**Note:** Methods that perform I/O operations require the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#PAGE_SIZE` Size of a MIFARE Ultralight page in bytes |
| `int` | `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_ULTRALIGHT` A MIFARE Ultralight tag |
| `int` | `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_ULTRALIGHT_C` A MIFARE Ultralight C tag |
| `int` | `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_UNKNOWN` A MIFARE Ultralight compatible tag of unknown type |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#close()() ` Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources. |
| ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#connect()() ` Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. |
| ` static https://developer.android.com/reference/android/nfc/tech/MifareUltralight` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#get(android.nfc.Tag)(https://developer.android.com/reference/android/nfc/Tag tag) ` Get an instance of `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` for the given tag. |
| ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#getMaxTransceiveLength()() ` Return the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])`. |
| ` https://developer.android.com/reference/android/nfc/Tag` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#getTag()() ` Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. |
| ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#getTimeout()() ` Get the current `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])` timeout in milliseconds. |
| ` int` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#getType()() ` Return the MIFARE Ultralight type of the tag. |
| ` boolean` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#isConnected()() ` Helper to indicate if I/O operations should be possible. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#readPages(int)(int pageOffset) ` Read 4 pages (16 bytes). |
| ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#setTimeout(int)(int timeout) ` Set the `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])` timeout in milliseconds. |
| ` byte[]` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])(byte[] data) ` Send raw NfcA data to a tag and receive the response. |
| ` void` | ` https://developer.android.com/reference/android/nfc/tech/MifareUltralight#writePage(int,%20byte[])(int pageOffset, byte[] data) ` Write 1 page (4 bytes). |

### 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/nfc/tech/TagTechnology ` ` abstract void` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()() `

Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources.
` abstract void` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect()() `

Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.
` abstract https://developer.android.com/reference/android/nfc/Tag` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#getTag()() `

Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.
` abstract boolean` ` https://developer.android.com/reference/android/nfc/tech/TagTechnology#isConnected()() `

Helper to indicate if I/O operations should be possible.
From interface ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### PAGE_SIZE

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

```
public static final int PAGE_SIZE
```

Size of a MIFARE Ultralight page in bytes

<br />

Constant Value: 4 (0x00000004)

### TYPE_ULTRALIGHT

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

```
public static final int TYPE_ULTRALIGHT
```

A MIFARE Ultralight tag

<br />

Constant Value: 1 (0x00000001)

### TYPE_ULTRALIGHT_C

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

```
public static final int TYPE_ULTRALIGHT_C
```

A MIFARE Ultralight C tag

<br />

Constant Value: 2 (0x00000002)

### TYPE_UNKNOWN

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

```
public static final int TYPE_UNKNOWN
```

A MIFARE Ultralight compatible tag of unknown type

<br />

Constant Value: -1 (0xffffffff)

## Public methods

### close

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

```
public void close ()
```

Disable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object, and release resources.

Also causes all blocked I/O operations on other thread to be canceled and return with `https://developer.android.com/reference/java/io/IOException`.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### connect

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

```
public void connect ()
```

Enable I/O operations to the tag from this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.

May cause RF activity and may block. Must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` by calling `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` from another thread.

Only one `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object can be connected to a `https://developer.android.com/reference/android/nfc/Tag` at a time.

Applications must call `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` when I/O operations are complete.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### get

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

```
public static MifareUltralight get (Tag tag)
```

Get an instance of `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` for the given tag.

Returns null if `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` was not enumerated in `https://developer.android.com/reference/android/nfc/Tag#getTechList()` - this indicates the tag is not MIFARE Ultralight compatible, or that this Android device does not implement MIFARE Ultralight.

Does not cause any RF activity and does not block.

<br />

| Parameters ||
|---|---|
| `tag` | `Tag`: an MIFARE Ultralight compatible tag <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/tech/MifareUltralight` | MIFARE Ultralight object <br /> |

### getMaxTransceiveLength

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

```
public int getMaxTransceiveLength ()
```

Return the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])`.

<br />

| Returns ||
|---|---|
| `int` | the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])`. <br /> |

### getTag

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

```
public Tag getTag ()
```

Get the `https://developer.android.com/reference/android/nfc/Tag` object backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/nfc/Tag` | the `https://developer.android.com/reference/android/nfc/Tag` backing this `https://developer.android.com/reference/android/nfc/tech/TagTechnology` object. <br /> |

### getTimeout

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

```
public int getTimeout ()
```

Get the current `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])` timeout in milliseconds.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Returns ||
|---|---|
| `int` | timeout value in milliseconds <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if the tag object is reused after the tag has left the field |

### getType

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

```
public int getType ()
```

Return the MIFARE Ultralight type of the tag.

One of `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_ULTRALIGHT` or `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_ULTRALIGHT_C` or `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#TYPE_UNKNOWN`.

Depending on how the tag has been formatted, it can be impossible to accurately classify between original MIFARE Ultralight and Ultralight C. So treat this method as a hint.

Does not cause any RF activity and does not block.

<br />

| Returns ||
|---|---|
| `int` | the type <br /> |

### isConnected

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

```
public boolean isConnected ()
```

Helper to indicate if I/O operations should be possible.

Returns true if `https://developer.android.com/reference/android/nfc/tech/TagTechnology#connect()` has completed, and `https://developer.android.com/reference/android/nfc/tech/TagTechnology#close()` has not been called, and the `https://developer.android.com/reference/android/nfc/Tag` is not known to be out of range.

Does not cause RF activity, and does not block.

<br />

| Returns ||
|---|---|
| `boolean` | true if I/O operations should be possible <br /> |

### readPages

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

```
public byte[] readPages (int pageOffset)
```

Read 4 pages (16 bytes).

The MIFARE Ultralight protocol always reads 4 pages at a time, to reduce the number of commands required to read an entire tag.

If a read spans past the last readable block, then the tag will return pages that have been wrapped back to the first blocks. MIFARE Ultralight tags have readable blocks 0x00 through 0x0F. So a read to block offset 0x0E would return blocks 0x0E, 0x0F, 0x00, 0x01. MIFARE Ultralight C tags have readable blocks 0x00 through 0x2B. So a read to block 0x2A would return blocks 0x2A, 0x2B, 0x00, 0x01.

This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#close()` is called from another thread.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Parameters ||
|---|---|
| `pageOffset` | `int`: index of first page to read, starting from 0 <br /> |

| Returns ||
|---|---|
| `byte[]` | 4 pages (16 bytes) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
| `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |

### setTimeout

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

```
public void setTimeout (int timeout)
```

Set the `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])` timeout in milliseconds.

The timeout only applies to `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])` on this object, and is reset to a default value when `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#close()` is called.

Setting a longer timeout may be useful when performing transactions that require a long processing time on the tag such as key generation.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Parameters ||
|---|---|
| `timeout` | `int`: timeout value in milliseconds <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if the tag object is reused after the tag has left the field |

### transceive

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

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

Send raw NfcA data to a tag and receive the response.

This is equivalent to connecting to this tag via `https://developer.android.com/reference/android/nfc/tech/NfcA` and calling `https://developer.android.com/reference/android/nfc/tech/NfcA#transceive(byte[])`. Note that all MIFARE Classic tags are based on `https://developer.android.com/reference/android/nfc/tech/NfcA` technology.

Use `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#getMaxTransceiveLength()` to retrieve the maximum number of bytes that can be sent with `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#transceive(byte[])`.

This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#close()` is called from another thread.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Parameters ||
|---|---|
| `data` | `byte` <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

**See also:**

- `https://developer.android.com/reference/android/nfc/tech/NfcA#transceive(byte[])`

### writePage

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

```
public void writePage (int pageOffset, 
                byte[] data)
```

Write 1 page (4 bytes).

The MIFARE Ultralight protocol always writes 1 page at a time, to minimize EEPROM write cycles.

This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with `https://developer.android.com/reference/java/io/IOException` if `https://developer.android.com/reference/android/nfc/tech/MifareUltralight#close()` is called from another thread.

Requires the `https://developer.android.com/reference/android/Manifest.permission#NFC` permission.

<br />

| Parameters ||
|---|---|
| `pageOffset` | `int`: index of page to write, starting from 0 <br /> |
| `data` | `byte`: 4 bytes to write <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/nfc/TagLostException` | if the tag leaves the field |
| `https://developer.android.com/reference/java/io/IOException` | if there is an I/O failure, or the operation is canceled |