NfcA
class NfcA : TagTechnology
kotlin.Any | |
↳ | 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
.
The primary NFC-A I/O operation is transceive
. Applications must implement their own protocol stack on top of transceive
.
Note: Methods that perform I/O operations require the android.Manifest.permission#NFC
permission.
Summary
Public methods | |
---|---|
Unit |
close() |
Unit |
connect() |
static NfcA! |
Get an instance of |
ByteArray! |
getAtqa() Return the ATQA/SENS_RES bytes from tag discovery. |
Int |
Return the maximum number of bytes that can be sent with |
Short |
getSak() Return the SAK/SEL_RES bytes from tag discovery. |
Tag! |
getTag() |
Int |
Get the current |
Boolean | |
Unit |
setTimeout(timeout: Int) Set the |
ByteArray! |
transceive(data: ByteArray!) Send raw NFC-A commands to the tag and receive the response. |
Public methods
close
fun close(): Unit
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error occurs |
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
connect
fun connect(): Unit
Exceptions | |
---|---|
TagLostException |
if the tag leaves the field |
java.io.IOException |
if there is an I/O failure, or connect is canceled |
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
get
static fun get(tag: Tag!): NfcA!
Get an instance of NfcA
for the given tag.
Returns null if NfcA
was not enumerated in Tag.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 |
Return | |
---|---|
NfcA! |
NFC-A object |
getAtqa
fun getAtqa(): ByteArray!
Return the ATQA/SENS_RES bytes from tag discovery.
Does not cause any RF activity and does not block.
Return | |
---|---|
ByteArray! |
ATQA/SENS_RES bytes |
getMaxTransceiveLength
fun getMaxTransceiveLength(): Int
Return the maximum number of bytes that can be sent with transceive
.
Return | |
---|---|
Int |
the maximum number of bytes that can be sent with transceive . |
getSak
fun getSak(): Short
Return the SAK/SEL_RES bytes from tag discovery.
Does not cause any RF activity and does not block.
Return | |
---|---|
Short |
SAK bytes |
getTag
fun getTag(): Tag!
Return | |
---|---|
Tag! |
the Tag backing this TagTechnology object. |
getTimeout
fun getTimeout(): Int
Get the current transceive
timeout in milliseconds.
Requires the android.Manifest.permission#NFC
permission.
Return | |
---|---|
Int |
timeout value in milliseconds |
Exceptions | |
---|---|
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
isConnected
fun isConnected(): Boolean
Return | |
---|---|
Boolean |
true if I/O operations should be possible |
setTimeout
fun setTimeout(timeout: Int): Unit
Set the transceive
timeout in milliseconds.
The timeout only applies to transceive
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 android.Manifest.permission#NFC
permission.
Parameters | |
---|---|
timeout |
Int: timeout value in milliseconds |
Exceptions | |
---|---|
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
transceive
fun transceive(data: ByteArray!): ByteArray!
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
.
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 android.Manifest.permission#NFC
permission.
Parameters | |
---|---|
data |
ByteArray!: bytes to send |
Return | |
---|---|
ByteArray! |
bytes received in response |
Exceptions | |
---|---|
TagLostException |
if the tag leaves the field |
java.io.IOException |
if there is an I/O failure, or this operation is canceled |