StackOverFlow:Android HCE: are there rules for AID?
主机卡模拟Demo 第一步 新建类CardEmulatorService 继承 HostApduService,实现方法 public byte[] processCommandApdu(byte[] commandApdu, Bundle extras)
@Override public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) { byte[] ret = null; Log.d("cyb", "processCommandApdu commandApdu=" + Hex.toHexString(commandApdu)); Toast.makeText(getApplicationContext(), Hex.toHexString(commandApdu), Toast.LENGTH_SHORT).show(); String MF_NAME = "1PAY.SYS.DDF01"; byte[] selectMF = Hex.hexToBytes("00A404000E" + Hex.toHexString(PbocCmd.MF_Name) + "00"); Log.d("cyb", "processCommandApdu selectMF=" + Hex.toHexString(selectMF)); if(Arrays.equals(commandApdu, selectMF)){ // 选择MF ret = Hex.hexToBytes("6F15840E315041592E5359532E4444463031A5038801019000"); }else if(Arrays.equals(commandApdu, Hex.hexToBytes("00A40000023F0100"))){ // 选择应用 ret = Hex.hexToBytes("6F088400A5049F0801029000"); }else if(Arrays.equals(commandApdu, Hex.hexToBytes("00A4000002000400"))){ // 选择文件 ret = Hex.hexToBytes("9000"); }else if(Arrays.equals(commandApdu, Hex.hexToBytes("00B0000000"))){ // 读文件 ret = Hex.hexToBytes("4F545142475535394352555245304D369000"); } Log.d("cyb", "processCommandApdu ret=" + Hex.toHexString(ret)); return ret; } 第二步 在res/xml 文件夹新建aid_list.xml
第三步 在AndroidManifest.xml中配置Service
读卡器代码 println("++++++++++++++ start ++++++++++++++++"); println("开始读文件..."); isoDep.connect(); Log.d("cyb", "Hex.toHexString(PbocCmd.MF_Name)=" + Hex.toHexString(PbocCmd.MF_Name)); // byte[] select_mf = PbocCmd.selectByName(isoDep, PbocCmd.MF_Name); byte[] select_mf = PbocCmd.selectByName(isoDep, PbocCmd.MF_Name); println("选择MF返回值=" + Hex.toHexString(select_mf)); if (IsoDepUtils.isNoError(select_mf)) { // 选择应用 byte[] appId = {0x3F, 0x01}; byte[] response = PbocCmd.selectById(isoDep, appId); if (IsoDepUtils.isNoError(response)) { println("选择文件=" + Hex.toHexString(appId)); println("选择文件返回值=" + Hex.toHexString(response)); println("卡文件名称=" + new SelectResult(response).getName());
} println("++++++++++++++ end ++++++++++++++++\n\n\n\n\n"); isoDep.close(); ———————————————— 版权声明:本文为CSDN博主「陈跃波」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/chenyuebo11/article/details/54894296