gpt4 book ai didi

java - 无法使用 javax.smartcardio.CardTerminal connect() 方法连接 Android HCE

转载 作者:行者123 更新时间:2023-11-30 02:40:18 26 4
gpt4 key购买 nike

所以现在我正在构建一个简单的应用程序来模拟使用 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 进行连接,结果相同。

我在代码中遗漏了什么吗?或者可能是技术问题?

编辑:我在我 friend 的 galaxy s iii 上安装了 apk 文件,它正在运行,所以我怀疑这是手机问题

最佳答案

如果我理解正确并且您的问题出在 Android 客户端上,您可能错过了在 list 和 xml 文件中为您的应用程序定义正确的 AID(另见 https://developer.android.com/guide/topics/connectivity/nfc/hce.html)您也可能只是注册了错误的 AID - 记录您的 apdu 命令以查看读者可能会寻求哪些帮助。

安卓 list :

 <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标签中填写你的AIDs):

 <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>

关于java - 无法使用 javax.smartcardio.CardTerminal connect() 方法连接 Android HCE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25862039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com