react-native-nfc-manager发SELECT APDU遇6A 82响应,求原因及正确命令
问题解答:HCE SELECT命令返回6A 82(文件未找到)
核心原因
6A 82响应本质是系统未匹配到你发送的AID对应的HCE应用,或是HCE应用错误地对SELECT命令返回该错误码(前者更常见)。
SELECT命令是否有误?
你的命令格式符合ISO 7816规范,但有两个细节可验证:
- AID字节完全匹配注册值
D2760000850101,这部分无问题。 - 末尾的
0x00是Le字段,表示期望接收最大长度响应,合法但部分设备可能存在兼容性问题。可尝试去掉Le字段,使用精简版命令:
const command = [ 0x00, 0xa4, 0x04, 0x00, 0x07, 0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 ];
HCE应用需检查的配置
- AID过滤配置:打开
res/xml/apduservice.xml,确认<aid-filter>完全匹配AID,且android:category设为other(避免系统优先支付类应用):<aid-group android:description="My HCE App" android:category="other"> <aid-filter android:name="D2760000850101"/> </aid-group> - 服务声明:在
AndroidManifest.xml中确认HCE服务的权限、intent-filter和meta-data配置正确:<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> - 系统默认应用设置:在设备「NFC > 卡模拟」设置中,将你的HCE设为对应AID的默认应用,避免被其他同AID应用拦截。
- 命令处理逻辑:检查
HostApduService的processCommandApdu方法,确保SELECT命令返回正确响应(如9000),而非错误地返回6A 82:@Override public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) { byte[] SELECT_AID = {0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x01}; if (Arrays.equals(SELECT_AID, commandApdu)) { return new byte[]{(byte)0x90, (byte)0x00}; // 成功响应 } return new byte[]{(byte)0x6A, (byte)0x82}; // 仅对非SELECT命令返回错误 }
读取应用需检查的配置
- 技术请求有效性:在
transceive前务必确认requestTechnology调用成功,避免无效的命令发送:const techSuccess = await NfcManager.requestTechnology([NfcTech.IsoDep]); if (!techSuccess) { console.log("IsoDep技术请求失败"); return; } - NFC权限:在
AndroidManifest.xml中添加必要权限:<uses-permission android:name="android.permission.NFC"/> <uses-feature android:name="android.hardware.nfc" android:required="true"/>
正确的SELECT APDU命令
针对你的AID,两种合法且兼容的命令形式:
- 带Le字段(请求最大长度响应):
const command = [0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01, 0x00];
- 不带Le字段(仅完成应用选择):
const command = [0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
优先测试第二种,排除Le字段的兼容性问题。
内容的提问来源于stack exchange,提问作者김지혜
相关产品推荐
相关产品推荐

