public final class NfcF
extends Object implements TagTechnology
| java.lang.Object | |
| android.nfc.tech.NfcF | |
提供对Tag的NFC-F(JIS 6319-4)属性和I / O操作的 Tag 。
主要的NFC-F I / O操作是transceive(byte[]) 。 应用程序必须在transceive(byte[])之上实现自己的协议栈。
注意:执行I / O操作的方法需要 NFC权限。
公共方法(Public methods) |
|
|---|---|
void |
close() 禁止对来自此 |
void |
connect() 对来自此 |
static NfcF |
get(Tag tag) 获取给定标签的 |
byte[] |
getManufacturer() 从标签发现中返回制造商字节。 |
int |
getMaxTransceiveLength() 返回可用 |
byte[] |
getSystemCode() 从标签发现中返回系统代码字节。 |
Tag |
getTag() 获取 |
int |
getTimeout() 以毫秒为单位获取当前的 |
boolean |
isConnected() 帮助者指出I / O操作是否可行。 |
void |
setTimeout(int timeout) 以毫秒为单位设置 |
byte[] |
transceive(byte[] data) 将原始NFC-F命令发送到标签并接收响应。 |
继承方法(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 |
|
NfcF get (Tag tag)
为给定标签获取 NfcF的实例。
如果NfcF未在getTechList()枚举,则返回null。 这表示标签不支持NFC-F。
不会导致任何RF活动并且不会阻止。
| 参数(Parameters) | |
|---|---|
tag |
Tag: an NFC-F compatible tag |
| 返回(Returns) | |
|---|---|
NfcF |
NFC-F object |
byte[] getManufacturer ()
从标签发现中返回制造商字节。
不会导致任何RF活动并且不会阻止。
| 返回(Returns) | |
|---|---|
byte[] |
Manufacturer bytes |
int getMaxTransceiveLength ()
返回可用 transceive(byte[])发送的最大字节数。
| 返回(Returns) | |
|---|---|
int |
the maximum number of bytes that can be sent with transceive(byte[]). |
byte[] getSystemCode ()
从标签发现中返回系统代码字节。
不会导致任何RF活动并且不会阻止。
| 返回(Returns) | |
|---|---|
byte[] |
System Code 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-F命令发送到标签并接收响应。
应用程序不能将SoD(前导码和同步码)作为前缀和/或将EoD(CRC)附加到有效载荷,它将自动计算。
这种方法的典型NFC-F帧如下所示:
LENGTH (1 byte) --- CMD (1 byte) -- IDm (8 bytes) -- PARAMS (LENGTH - 10 bytes)
使用 getMaxTransceiveLength()检索可以使用 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 |