如何使用 Android NFC 从智能卡上的具体 ACID 发出 SELECT 命令

How can I make SELECT command from concret AID on Smart Card with Android NFC

我尝试通过 NFC 和 Android 从智能卡读取数据。

我有带应用程序的智能卡。应用程序有 AID(应用程序 ID)A0000006581010

我需要制作 SELECT 命令并读取结果。

我写的方法:

private static final String SAMPLE_LOYALTY_CARD_AID = "F222222222";

private void performTransaction(Intent nfcIntent) {
        Tag tagFromIntent = nfcIntent.getParcelableExtra(EXTRA_TAG);
        NfcA mNfc = NfcA.get(tagFromIntent);
        try {
            mNfc.connect();

            //I can read ID
            byte[] id = mNfc.getTag().getId();

            //I tried create SELECT command
            byte[] selCommand = BuildSelectApdu(SAMPLE_LOYALTY_CARD_AID);
            //I try send command to card
            byte[] result = mNfc.transceive(selCommand);
            //I get result == {106, -126}
        } catch (IOException e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        } finally {
            if (mNfc != null) {
                try {
                    mNfc.close();
                } catch (IOException e) {
                    Log.v("tag", "error closing the tag");
                }
            }
        }
    }

如何从智能卡上的具体 AID 发出 SELECT 命令?

SELECT是一个标准的APDU命令,你可以从Global Platform中找到定义它的规范。 从 AID 构建它非常机械:

00A40400 + AID lenght in hexadecimal + AID + 00

例如,对于 A0000006581010 的 AID,SELECT 命令是:

00A4040007A000000658101000