1

所以现在我正在构建一个简单的应用程序来模拟使用 Android HCE(基于主机的卡模拟)的智能卡。该应用程序只为其接收到的每个 APDU 命令返回 {90,00} 字节数组。这是代码:

public class MyHostApduService extends HostApduService {

    @Override
    public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
        byte[] response = new byte[2];
        response[0] = (byte)0x90;
        response[1] = 0x00;
        return response;
    }

    //Rest of the code...
}

然后我尝试使用 javax.smartcardio.CardTerminal 中的 CardTerminal.connect() 方法将我的智能手机(我使用的是 Sony Xperia M2)连接到智能卡读卡器(ACR122U-A9),如下所示

Card card = terminal.connect("*");

它适用于真正的智能卡,但它不想连接我的手机。发出哔声,但 LED 关闭(它不像检测到真正的智能卡时那样变成绿色),当我移除智能手机时,我收到 CardException,LED 灯又变回红色。有时阅读器看起来像是连接到手机(LED 变为绿色),但手机似乎没有收到 APDU。我还尝试使用 springcard 中的 scScriptor.exe 进行连接,结果相同。

代码上有什么我想念的吗?或者可能是技术问题?

编辑:我在朋友的galaxy s iii上安装了apk文件,它正在工作,所以我怀疑这是电话问题

4

1 回答 1

1

如果我理解这一点并且您的问题出在 Android 客户端上,您可能错过了在清单和 xml 文件中为您的应用程序定义正确的 AID(另请参阅https://developer.android.com/guide/ topic/connectivity/nfc/hce.html)您可能还注册了错误的 AID - 记录您的 apdu-commands 以查看读者可能会寻求哪些帮助。

安卓清单:

 <service android:name=".MyHostApduService" android:exported="true"
         android:permission="android.permission.BIND_NFC_SERVICE">
    <intent-filter>
        <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE"/>
    </intent-filter>
    <meta-data android:name="android.nfc.cardemulation.host_apdu_service"
               android:resource="@xml/apduservice"/>
</service>

apduservice.xml(在aid-filter标签中填写你的AID):

 <host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
           android:description="@string/servicedesc"
           android:requireDeviceUnlock="false">
    <aid-group android:description="@string/aiddescription"
               android:category="other">
        <aid-filter android:name="F0010203040506"/>
        <aid-filter android:name="F0394148148100"/>
    </aid-group>
</host-apdu-service>
于 2014-09-16T15:56:12.753 回答