1

使用标签的收发方法发送 SELECT PPSE 命令时出现标签丢失异常。

意图被传递给readTag并且该方法正在从意图中获取标签,但是为 SELECT PPSE 命令 APDU 调用收发方法会导致标签丢失异常,而不是获取响应 APDU 消息:

public void readTag(Intent intent) {
    String action = intent.getAction();
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
        System.out.println("Got the tag");
        Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NfcA mfc = NfcA.get(tagFromIntent);
        System.out.println(mfc);
        try {
            mfc.connect();
            System.out.println(mfc.getTag());
            System.out.println(mfc.getClass());
            byte[] ATQA = mfc.getAtqa();
            System.out.println(getHexString(ATQA));
            System.out.println(mfc.getMaxTransceiveLength());
            mfc.setTimeout(500000);

            String value = "00A404000e325041592e5359532e444446303100"; //PPSE APDU value
            String hex = value.toString();
            byte[] data = HexToByte(hex);
            byte[] response = mfc.transceive(data); //sending request
            System.out.println(getHexString(response));
            mfc.close();
        } catch(Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(),
                           Toast.LENGTH_SHORT).show();
        }
    }
}
4

1 回答 1

1

标签技术NfcA(以及NfcB)用于使用 ISO 14443-3 专有命令集进行通信。APDU 通常在 ISO-DEP / T=CL(ISO 14443-4 传输协议)之上发送,因此您可能希望使用IsoDep标签技术而不是NfcA.

此外,您可能希望使用稍低的超时值。通常,大约 1 到 10 秒的值就足够了(到目前为止)——除非您在智能卡上触发了一些复杂的操作。

于 2014-02-10T18:21:24.027 回答