# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Constants | Methods | Inherited Methods

# MifareUltralight

`public final class MifareUltralight`
`extends Object` `implements TagTechnology`

java.lang.Object
↳ | android.nfc.tech.MifareUltralight

Provides access to MIFARE Ultralight properties and I/O operations on a `Tag`.

Acquire a `MifareUltralight` object using `get(Tag)`.

MIFARE Ultralight compatible tags have 4 byte pages `PAGE_SIZE`. The primary operations on an Ultralight tag are `readPages(int)` and `writePage(int, byte[])`.

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 `MifareUltralight` will never be enumerated in `Tag#getTechList`. If it is enumerated, then all `MifareUltralight` I/O operations will be supported. In either case, `NfcA` will also be enumerated on the tag, because all MIFARE Ultralight tags are also `NfcA` tags.

Note: Methods that perform I/O operations require the `Manifest.permission.NFC` permission.

## Summary

### Constants
`int` | `PAGE_SIZE` Size of a MIFARE Ultralight page in bytes
`int` | `TYPE_ULTRALIGHT` A MIFARE Ultralight tag
`int` | `TYPE_ULTRALIGHT_C` A MIFARE Ultralight C tag
`int` | `TYPE_UNKNOWN` A MIFARE Ultralight compatible tag of unknown type

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

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `android.nfc.tech.TagTechnology`
`abstract void` | `close()` Disable I/O operations to the tag from this `TagTechnology` object, and release resources.
`abstract void` | `connect()` Enable I/O operations to the tag from this `TagTechnology` object.
`abstract Tag` | `getTag()` Get the `Tag` object backing this `TagTechnology` object.
`abstract boolean` | `isConnected()` Helper to indicate if I/O operations should be possible.
From interface `java.io.Closeable`
`abstract void` | `close()` Closes this stream and releases any system resources associated with it.
From interface `java.lang.AutoCloseable`
`abstract void` | `close()` Closes this resource, relinquishing any underlying resources.

## Constants

### PAGE_SIZE

    public static final int PAGE_SIZE

Size of a MIFARE Ultralight page in bytes

Constant Value: 4 (0x00000004)

### TYPE_ULTRALIGHT

    public static final int TYPE_ULTRALIGHT

A MIFARE Ultralight tag

Constant Value: 1 (0x00000001)

### TYPE_ULTRALIGHT_C

    public static final int TYPE_ULTRALIGHT_C

A MIFARE Ultralight C tag

Constant Value: 2 (0x00000002)

### TYPE_UNKNOWN

    public static final int TYPE_UNKNOWN

A MIFARE Ultralight compatible tag of unknown type

Constant Value: -1 (0xffffffff)

## Public methods

### close

    public void close ()

Disable I/O operations to the tag from this `TagTechnology` object, and release resources.

Also causes all blocked I/O operations on other thread to be canceled and return with `IOException`.

Requires the `Manifest.permission.NFC` permission.

Throws
`IOException` |

### connect

    public void connect ()

Enable I/O operations to the tag from this `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 `IOException` by calling `close()` from another thread.

Only one `TagTechnology` object can be connected to a `Tag` at a time.

Applications must call `close()` when I/O operations are complete.

Requires the `Manifest.permission.NFC` permission.

Throws
`IOException` |

### get

    public static MifareUltralight get (Tag tag)

Get an instance of `MifareUltralight` for the given tag.

Returns null if `MifareUltralight` was not enumerated in `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.

Parameters
`tag` | `Tag`: an MIFARE Ultralight compatible tag

Returns
`MifareUltralight` | MIFARE Ultralight object

### getMaxTransceiveLength

    public int getMaxTransceiveLength ()

Return the maximum number of bytes that can be sent with `transceive(byte[])`.

Returns
`int` | the maximum number of bytes that can be sent with `transceive(byte[])`.

### getTag

    public Tag getTag ()

Get the `Tag` object backing this `TagTechnology` object.

Returns
`Tag` | the `Tag` backing this `TagTechnology` object.

### getTimeout

    public int getTimeout ()

Get the current `transceive(byte[])` timeout in milliseconds.

Requires the `Manifest.permission.NFC` permission.

Returns
`int` | timeout value in milliseconds

### getType

    public int getType ()

Return the MIFARE Ultralight type of the tag.

One of `TYPE_ULTRALIGHT` or `TYPE_ULTRALIGHT_C` or `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.

Returns
`int` | the type

### isConnected

    public boolean isConnected ()

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

Returns true if `connect()` has completed, and `close()` has not been called, and the `Tag` is not known to be out of range.

Does not cause RF activity, and does not block.

Returns
`boolean` | true if I/O operations should be possible

### readPages

    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 `IOException` if `close()` is called from another thread.

Requires the `Manifest.permission.NFC` permission.

Parameters
`pageOffset` | `int`: index of first page to read, starting from 0

Returns
`byte[]` | 4 pages (16 bytes)

Throws
`TagLostException` | if the tag leaves the field
`IOException` | if there is an I/O failure, or the operation is canceled

### setTimeout

    public void setTimeout (int timeout)

Set the `transceive(byte[])` timeout in milliseconds.

The timeout only applies to `transceive(byte[])` on this object, and is reset to a default value when `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 `Manifest.permission.NFC` permission.

Parameters
`timeout` | `int`: timeout value in milliseconds

### transceive

    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 `NfcA` and calling `NfcA#transceive`. Note that all MIFARE Classic tags are based on `NfcA` technology.

Use `getMaxTransceiveLength()` to retrieve the maximum number of bytes that can be sent with `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 `IOException` if `close()` is called from another thread.

Requires the `Manifest.permission.NFC` permission.

Parameters
`data` | `byte`

Returns
`byte[]` |

Throws
`IOException` |

See also:

- `NfcA.transceive(byte[])`

### writePage

    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 `IOException` if `close()` is called from another thread.

Requires the `Manifest.permission.NFC` permission.

Parameters
`pageOffset` | `int`: index of page to write, starting from 0
`data` | `byte`: 4 bytes to write

Throws
`TagLostException` | if the tag leaves the field
`IOException` | if there is an I/O failure, or the operation is canceled

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*