public final class NfcA
extends Object implements TagTechnology
| java.lang.Object | |
| android.nfc.tech.NfcA | |
提供对Tag的NFC-A(ISO 14443-3A)属性和I / O操作的 Tag 。
主要的NFC-A I / O操作是transceive(byte[]) 。 应用程序必须在transceive(byte[])之上实现自己的协议栈。
注意:执行I / O操作的方法需要 NFC权限。
公共方法(Public methods) |
|
|---|---|
void |
close() 禁用对来自此 |
void |
connect() 对来自此 |
static NfcA |
get(Tag tag) 获取给定标签的实例 |
byte[] |
getAtqa() 从标签发现中返回ATQA / SENS_RES字节。 |
int |
getMaxTransceiveLength() 返回可用 |
short |
getSak() 从标签发现中返回SAK / SEL_RES字节。 |
Tag |
getTag() 获取 |
int |
getTimeout() 以毫秒为单位获取当前的 |
boolean |
isConnected() 帮助者指出I / O操作是否可行。 |
void |
setTimeout(int timeout) 以毫秒为单位设置 |
byte[] |
transceive(byte[] data) 将原始NFC-A命令发送到标签并接收响应。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.nfc.tech.TagTechnology
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
void close ()
禁用对来自此 TagTechnology对象的标记的I / O操作,并释放资源。
还会导致其他线程上的所有被阻止的I / O操作被取消,并返回 IOException 。
需要 NFC权限。
| 抛出异常(Throws) | |
|---|---|
IOException |
|
void connect ()
启用来自此 TagTechnology对象的标记的I / O操作。
可能导致RF活动并可能阻塞。 不能从主应用程序线程调用。 IOException通过从另一个线程调用close()来阻止呼叫将被取消。
一次只能将一个 TagTechnology对象连接到 Tag 。
当I / O操作完成时,应用程序必须调用 close() 。
需要 NFC权限。
| 抛出异常(Throws) | |
|---|---|
IOException |
|
NfcA get (Tag tag)
获取给定标签的实例 NfcA 。
如果NfcA未在getTechList()枚举,则返回null。 这表示标签不支持NFC-A。
不会导致任何RF活动并且不会阻止。
| 参数(Parameters) | |
|---|---|
tag |
Tag: an NFC-A compatible tag |
| 返回(Returns) | |
|---|---|
NfcA |
NFC-A object |
byte[] getAtqa ()
从标签发现中返回ATQA / SENS_RES字节。
不会导致任何RF活动并且不会阻止。
| 返回(Returns) | |
|---|---|
byte[] |
ATQA/SENS_RES bytes |
int getMaxTransceiveLength ()
返回可用 transceive(byte[])发送的最大字节数。
| 返回(Returns) | |
|---|---|
int |
the maximum number of bytes that can be sent with transceive(byte[]). |
short getSak ()
从标签发现中返回SAK / SEL_RES字节。
不会导致任何RF活动并且不会阻止。
| 返回(Returns) | |
|---|---|
short |
SAK bytes |
Tag getTag ()
获取 Tag对象支持此 TagTechnology对象。
| 返回(Returns) | |
|---|---|
Tag |
the Tag backing this TagTechnology object. |
int getTimeout ()
以毫秒为单位获取当前的 transceive(byte[])超时。
需要 NFC权限。
| 返回(Returns) | |
|---|---|
int |
timeout value in milliseconds |
boolean isConnected ()
帮助者指出I / O操作是否可行。
如果返回true connect()已经完成,并 close()没有被调用,并且 Tag不知道是超出范围。
不会导致射频活动,也不会阻止。
| 返回(Returns) | |
|---|---|
boolean |
true if I/O operations should be possible |
void setTimeout (int timeout)
以毫秒为单位设置 transceive(byte[])超时。
超时仅适用于此对象上的 transceive(byte[]) ,并在 close()时重置为默认值。
在标签上执行需要较长处理时间的事务(例如密钥生成)时,设置较长的超时时间可能很有用。
需要 NFC权限。
| 参数(Parameters) | |
|---|---|
timeout |
int: timeout value in milliseconds |
byte[] transceive (byte[] data)
将原始NFC-A命令发送到标签并接收响应。
应用程序不能将EoD(CRC)附加到有效负载,它将自动计算。
应用程序只能发送完整字节的命令,例如SENS_REQ不可用(这些用于管理标记轮询和初始化)。
使用 getMaxTransceiveLength()可检索可通过 transceive(byte[])发送的最大字节数。
这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。
需要 NFC权限。
| 参数(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 |