我尝试将 ACR122 集成到我的 android 应用程序中。我正在使用ACS 提供的 ANDROID 库( http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/ )。
一切正常,我可以检测到卡的存在,但我想提取卡的 UID/ID。有人知道这样做的功能吗?
你有这种集成的例子吗?
我尝试将 ACR122 集成到我的 android 应用程序中。我正在使用ACS 提供的 ANDROID 库( http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/ )。
一切正常,我可以检测到卡的存在,但我想提取卡的 UID/ID。有人知道这样做的功能吗?
你有这种集成的例子吗?
如果是 Mifare 卡,您需要将此 APDU 字节数组发送到卡:(byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00
. 我不确定 ACR122 API,但可能您需要将此 APDU 包装到特定的 API 方法中,例如传输()
更新
示例代码:
byte[] command = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
byte[] response = new byte[300];
int responseLength;
responseLength = reader.transmit(slotNum, command, command.length, response,response.length);
System.out.println(new String(response));
Reader
是com.acs.smartcard.Reader
对象并且slotNum
是插槽号。我不确定如何找到它,因为我没有要测试的 ACR。但是如果你告诉你能够与读者建立基本的通信,你可能知道 slotNum。
为了防止在尝试读取 UID 时出现此错误:
com.acs.smartcard.InvalidDeviceStateException:当前状态不等于特定。
这应该是:
int slotNum = 0;
byte[] payload = new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
byte[] response = new byte[7]; // 7 bytes + 90 00 (9 bytes)
try {
reader.power(slotNum, Reader.CARD_WARM_RESET);
reader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);
reader.transmit(slotNum, payload, payload.length, response, response.length);
logBuffer(response, response.length);
} catch (ReaderException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}