Android通过USBHost与Gemalto智能卡通信以读取CIN
创始人
2024-08-21 18:00:10
0

在Android应用程序中实现与智能卡的通信时,可以使用Android提供的USB Host功能。这种方法可以实现通过USB接口与智能卡之间的通信。以下是一个可能的实现示例:

  1. 在AndroidManifest.xml文件中添加以下权限:

  1. 在Activity中添加以下代码:

private void readCIN() { UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); UsbDevice device = null; for (UsbDevice usbDevice : manager.getDeviceList().values()) { if (usbDevice.getProductId() == PRODUCT_ID && usbDevice.getVendorId() == VENDOR_ID) { device = usbDevice; break; } } if (device != null) { PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); registerReceiver(usbReceiver, filter);

    manager.requestPermission(device, permissionIntent);
}

}

private final BroadcastReceiver usbReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                UsbInterface usbInterface = device.getInterface(0);
                UsbEndpoint usbEndpoint = usbInterface.getEndpoint(0);

                UsbDeviceConnection connection = manager.openDevice(device);
                connection.claimInterface(usbInterface, true);

                byte[] buffer = new byte[256];
                int length = connection.bulkTransfer(usbEndpoint, buffer, buffer.length, 1000);

                if (length > 0) {
                    // 处理智能卡返回的数据
                }
            } else {
                // 权限请求被拒绝
            }
        }
    }
}

};

  1. 从智能卡中读取CIN数据:

// 在onReceive方法中添加智能卡通信代码

// 发送APDU命令到智能卡 byte[] command = { 0x00,0xA4,0x04,0x00,0x08,AID,0x01,0x02,0x03,0x

相关内容

热门资讯

普及透视!菠萝辅助器免费版的功... 普及透视!菠萝辅助器免费版的功能介绍!都是是真的有辅助方法(有挂规律)-哔哩哔哩1、打开软件启动之后...
解谜透视!wepoker辅助器... 解谜透视!wepoker辅助器如何使用,德州辅助工具到底怎么样,总结教程(详细教程)-哔哩哔哩1、德...
解密透视!werplan怎么透... 解密透视!werplan怎么透视!确实有辅助软件(有挂存在)-哔哩哔哩1、完成werplan怎么透视...
了解透视!德州局脚本,poke... 了解透视!德州局脚本,pokemmo手机版脚本免费,方式教程(有挂存在)-哔哩哔哩1、首先打开pok...
曝光透视!pokemmo脚本!... 曝光透视!pokemmo脚本!总是真的有辅助教程(证实有挂)-哔哩哔哩1、玩家可以在pokemmo脚...
揭幕透视!aa poker辅助... 揭幕透视!aa poker辅助包,wepoker作必弊视频,方式教程(有挂功能)-哔哩哔哩1、完成w...
关于透视!wepoker私人定... 关于透视!wepoker私人定制透视,xpoker辅助神器,妙计教程(真实有挂)-哔哩哔哩1、游戏颠...
科普透视!来玩德州破解器!原来... 科普透视!来玩德州破解器!原来真的有辅助app(有挂方法)-哔哩哔哩1、科普透视!来玩德州破解器!原...
科普透视!hhpoker怎么破... 科普透视!hhpoker怎么破解,pokemmo脚本辅助器,窍门教程(有挂解惑)-哔哩哔哩1、玩家可...
揭露透视!智星德州插件2024... 揭露透视!智星德州插件2024最新版!原来真的是有辅助神器(发现有挂)-哔哩哔哩1、进入到智星德州插...