public final class MifareUltralight
extends Object implements TagTechnology
| java.lang.Object | |
| android.nfc.tech.MifareUltralight | |
提供对 Tag上的MIFARE Ultralight属性和I / O操作的 Tag 。
使用 get(Tag)获取 MifareUltralight对象。
MIFARE Ultralight兼容标签有4个字节的页面PAGE_SIZE 。 Ultralight标签的主要操作是readPages(int)和writePage(int, byte[]) 。
原始的MIFARE Ultralight由一个64字节的EEPROM组成。 前4个页面用于OTP区域,制造商数据和锁定位。 它们是可读的,有些位是可写的。 最后12页是用户读/写区域。 欲了解更多信息,请参阅恩智浦数据表MF0ICU1。
MIFARE Ultralight C由一个192字节的EEPROM组成。 前4页用于OTP,制造商数据和锁定位。 接下来的36页是用户读/写区域。 接下来的4页是额外的锁定位,计数器和认证配置,并且是可读的。 最后4页用于验证密钥并且不可读。 欲了解更多信息,请参阅恩智浦数据表MF0ICU2。
在Android NFC设备上实现此类是可选的。 如果它没有实现,那么MifareUltralight将永远不会被枚举到getTechList() 。 如果枚举,则将支持所有MifareUltralight I / O操作。 无论哪种情况, NfcA也将枚举在标签上,因为所有MIFARE Ultralight标签也都是NfcA标签。
注意:执行I / O操作的方法需要 NFC权限。
常量(Constants) |
|
|---|---|
int |
PAGE_SIZE MIFARE Ultralight页面的大小(以字节为单位) |
int |
TYPE_ULTRALIGHT MIFARE Ultralight标签 |
int |
TYPE_ULTRALIGHT_C MIFARE Ultralight C标签 |
int |
TYPE_UNKNOWN 未知类型的MIFARE Ultralight兼容标签 |
公共方法(Public methods) |
|
|---|---|
void |
close() 禁用来自此 |
void |
connect() 对来自此 |
static MifareUltralight |
get(Tag tag) 为给定标签获取 |
int |
getMaxTransceiveLength() 返回可以用 |
Tag |
getTag() 获取 |
int |
getTimeout() 以毫秒为单位获取当前 |
int |
getType() 返回标签的MIFARE Ultralight类型。 |
boolean |
isConnected() 帮助者指出I / O操作是否可行。 |
byte[] |
readPages(int pageOffset) 阅读4页(16字节)。 |
void |
setTimeout(int timeout) 以毫秒为单位设置 |
byte[] |
transceive(byte[] data) 将原始NfcA数据发送到标签并接收响应。 |
void |
writePage(int pageOffset, byte[] data) 写1页(4字节)。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.nfc.tech.TagTechnology
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
int TYPE_ULTRALIGHT_C
MIFARE Ultralight C标签
常量值:2(0x00000002)
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 |
|
MifareUltralight get (Tag tag)
为给定标签获取 MifareUltralight的实例。
如果未在 getTechList()枚举 MifareUltralight则返回null - 这表示该标签不是与MIFARE Ultralight兼容的,或者此Android设备未实现MIFARE Ultralight。
不会导致任何RF活动并且不会阻止。
| 参数(Parameters) | |
|---|---|
tag |
Tag: an MIFARE Ultralight compatible tag |
| 返回(Returns) | |
|---|---|
MifareUltralight |
MIFARE Ultralight object |
int getMaxTransceiveLength ()
返回可用 transceive(byte[])发送的最大字节数。
| 返回(Returns) | |
|---|---|
int |
the maximum number of bytes that can be sent with transceive(byte[]). |
Tag getTag ()
获取 Tag对象支持此 TagTechnology对象。
| 返回(Returns) | |
|---|---|
Tag |
the Tag backing this TagTechnology object. |
int getTimeout ()
以毫秒为单位获取当前的 transceive(byte[])超时。
需要 NFC权限。
| 返回(Returns) | |
|---|---|
int |
timeout value in milliseconds |
int getType ()
返回标签的MIFARE Ultralight类型。
TYPE_ULTRALIGHT或 TYPE_ULTRALIGHT_C或 TYPE_UNKNOWN 。
根据标签如何格式化,在原始MIFARE Ultralight和Ultralight C之间进行准确分类是不可能的。因此,将此方法作为提示对待。
不会导致任何RF活动并且不会阻止。
| 返回(Returns) | |
|---|---|
int |
the type |
boolean isConnected ()
帮助者指出I / O操作是否可行。
如果返回true connect()已经完成,并 close()没有被调用,并且 Tag不知道是超出范围。
不会导致射频活动,也不会阻止。
| 返回(Returns) | |
|---|---|
boolean |
true if I/O operations should be possible |
byte[] readPages (int pageOffset)
阅读4页(16字节)。
MIFARE Ultralight协议每次总是读取4页,以减少读取整个标签所需的命令数量。
如果读取跨越最后一个可读块,那么标记将返回已经回卷到第一个块的页面。 MIFARE Ultralight标签具有可读块0x00至0x0F。 因此,读取以阻止偏移量0x0E将返回块0x0E,0x0F,0x00,0x01。 MIFARE Ultralight C标签具有可读块0x00至0x2B。 因此,读取阻止0x2A会返回块0x2A,0x2B,0x00,0x01。
这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。
需要 NFC权限。
| 参数(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 |
void setTimeout (int timeout)
以毫秒为单位设置 transceive(byte[])超时。
超时仅适用于此对象上的 transceive(byte[]) ,并在 close()时重置为默认值。
在标签上执行需要较长处理时间的事务(例如密钥生成)时,设置较长的超时时间可能很有用。
需要 NFC权限。
| 参数(Parameters) | |
|---|---|
timeout |
int: timeout value in milliseconds |
byte[] transceive (byte[] data)
将原始NfcA数据发送到标签并接收响应。
这相当于通过NfcA连接到此标签并致电transceive(byte[]) 。 请注意,所有MIFARE Classic标签均基于NfcA技术。
使用 getMaxTransceiveLength()检索可以与发送的字节的最大数量 transceive(byte[]) 。
这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被IOException取消。
需要 NFC权限。
| 参数(Parameters) | |
|---|---|
data |
byte
|
| 返回(Returns) | |
|---|---|
byte[] |
|
| 抛出异常(Throws) | |
|---|---|
IOException |
|
也可以看看:
void writePage (int pageOffset,
byte[] data)
写1页(4字节)。
MIFARE Ultralight协议每次总是写入1页,以尽量减少EEPROM写入周期。
这是一个I / O操作,将阻塞直到完成。 它不能从主应用程序线程调用。 如果从另一个线程调用close()被阻止的呼叫将被取消, IOException 。
需要 NFC权限。
| 参数(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 |