Skip to content

Most visited

Recently visited

navigation

NfcA

public final class NfcA
extends Object implements TagTechnology

java.lang.Object
   ↳ android.nfc.tech.NfcA


Provides access to NFC-A (ISO 14443-3A) properties and I/O operations on a Tag.

Acquire a NfcA object using get(Tag).

The primary NFC-A I/O operation is transceive(byte[]). Applications must implement their own protocol stack on top of transceive(byte[]).

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

Summary

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 NfcA get(Tag tag)

Get an instance of NfcA for the given tag.

byte[] getAtqa()

Return the ATQA/SENS_RES bytes from tag discovery.

int getMaxTransceiveLength()

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

short getSak()

Return the SAK/SEL_RES bytes from tag discovery.

Tag getTag()

Get the Tag object backing this TagTechnology object.

int getTimeout()

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

boolean isConnected()

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

void setTimeout(int timeout)

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

byte[] transceive(byte[] data)

Send raw NFC-A commands to the tag and receive the response.

Inherited methods

From class java.lang.Object
From interface android.nfc.tech.TagTechnology
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public methods

close

Added in API level 10
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 NFC permission.

Throws
IOException

connect

Added in API level 10
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 NFC permission.

Throws
IOException

get

Added in API level 10
NfcA get (Tag tag)

Get an instance of NfcA for the given tag.

Returns null if NfcA was not enumerated in getTechList(). This indicates the tag does not support NFC-A.

Does not cause any RF activity and does not block.

Parameters
tag Tag: an NFC-A compatible tag
Returns
NfcA NFC-A object

getAtqa

Added in API level 10
byte[] getAtqa ()

Return the ATQA/SENS_RES bytes from tag discovery.

Does not cause any RF activity and does not block.

Returns
byte[] ATQA/SENS_RES bytes

getMaxTransceiveLength

Added in API level 14
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[]).

getSak

Added in API level 10
short getSak ()

Return the SAK/SEL_RES bytes from tag discovery.

Does not cause any RF activity and does not block.

Returns
short SAK bytes

getTag

Added in API level 10
Tag getTag ()

Get the Tag object backing this TagTechnology object.

Returns
Tag the Tag backing this TagTechnology object.

getTimeout

Added in API level 14
int getTimeout ()

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

Requires the NFC permission.

Returns
int timeout value in milliseconds

isConnected

Added in API level 10
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

setTimeout

Added in API level 14
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 NFC permission.

Parameters
timeout int: timeout value in milliseconds

transceive

Added in API level 10
byte[] transceive (byte[] data)

Send raw NFC-A commands to the tag and receive the response.

Applications must not append the EoD (CRC) to the payload, it will be automatically calculated.

Applications must only send commands that are complete bytes, for example a SENS_REQ is not possible (these are used to manage tag polling and initialization).

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 NFC permission.

Parameters
data byte: bytes to send
Returns
byte[] bytes received in response
Throws
if the tag leaves the field
IOException if there is an I/O failure, or this operation is canceled
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.