【问题标题】:ACR122 - Android / How to extract the UIDACR122 - Android / 如何提取 UID
【发布时间】:2015-07-01 07:26:00
【问题描述】:

我尝试将 ACR122 集成到我的 Android 应用程序中。我正在使用 ACS 提供的 ANDROID 库 (http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/)。

一切正常,我可以检测到卡的存在,但我想提取卡的 UID/ID。有人知道这样做的功能吗?

你有这种集成的例子吗?

【问题讨论】:

  • 你问这个完全相同的问题有什么原因吗(另一个在这里:stackoverflow.com/q/29804329/2425802)?如果您想编辑您的问题,请使用它下面的 edit 链接。
  • 留下一个有效的更新答案。

标签: android nfc acr122


【解决方案1】:

如果是 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));

Readercom.acs.smartcard.Reader 对象 slotNum 是插槽号。我不确定如何找到它,因为我没有要测试的 ACR。但是,如果您告诉您能够与 reader 建立基本通信,您可能知道 slotNum。

【讨论】:

  • 当我使用该语法时,它会抛出“Com.Acs.Smartcard.InvalidDeviceStateException:当前状态不等于特定状态。” ACR122 API 是否还需要其他步骤?
  • @ChrisMiller 我遇到了同样的错误。你解决过这个问题吗?
  • @BradBeighton 我想你需要先做一些初始化: reader.power(slotNum, Reader.CARD_WARM_RESET); reader.setProtocol(slotNum, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);
  • 嗨@AndreySabitov,你是对的,你必须先做这两件事。这对我有用: mReader.power(0, Reader.CARD_WARM_RESET); mReader.setProtocol(0, Reader.PROTOCOL_T0 | Reader.PROTOCOL_T1);
【解决方案2】:

为了防止在尝试读取 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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-21
    • 2015-05-09
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    相关资源
    最近更新 更多