本Demo需要华视的身份证读卡器,连接Android机器设备,当身份证读卡器读取到身份证信息后,立马展示出身份证信息数据。得到身份证的姓名、照片、出生年月等数据。
本Demo需要华视的身份证读卡器,连接Android机器设备,当身份证读卡器读取到身份证信息后,立马展示出身份证信息数据。得到身份证的姓名、照片、出生年月等数据。
本Demo需要华视的身份证读卡器,连接Android机器设备,当身份证读卡器读取到身份证信息后,立马展示出身份证信息数据。得到身份证的姓名、照片、出生年月等数据。
app module 依赖libraries 目录下的FaceVerifyModel和ReadIDCardModel。我们对身份证读卡的sdk做了简单的封装。我们无需理会读卡的具体过程,我可以再本片文章做简单的解释,以便你更快的理解我封装的sdk运行原理读卡原理。
要一直读卡,那么一定会有一个子线程while(true)一直读卡,直到程序停止,app退出,那么这个线程结束。我们要用一个线程控制。。
private class AlwaysReadCardRunnable implements Runnable {
@Override
public void run() {
HSIDCardInfo icCardInfo;
while (isAutoReadCard) {
synchronized (hsOtgApi) {
//读取成功阻塞3秒
SystemClock.sleep(4 * 100);
if (hsOtgApi.Authenticate(200, 200) != 1) {
Log.i(TAG, "卡认证失败");
//SystemClock.sleep(1 * 1000);
SystemClock.sleep(1 * 1000);
} else {
icCardInfo = new HSIDCardInfo();
ReadCardEvent cardEvent = new ReadCardEvent();
if (hsOtgApi.ReadCard(icCardInfo, 200, 1300) == 1) {
int ret = hsOtgApi.Unpack(filepath, icCardInfo.getwltdata());// 照片解码
if (ret != 0) {
Log.i(TAG, "unzip success");
}
cardEvent.setCardInfo(icCardInfo);
EventBus.getDefault().post(cardEvent);
Log.i(TAG, "读卡成功");
SystemClock.sleep(5 * 100);
}
else{
Log.i(TAG, "读卡shibai");
}
//SystemClock.sleep(3 * 1000);
}
}
}
}
}
Activity的创建后初始化此sdk
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new VerifyPresenter((VerifyContract.View) fragment, new VerifyModel());
IDCardSDK.getInstance().initSDK(getHandler(), this);
}
public class IdCardBean {
private String name;
private String gender;
private String people;//民族;
private String from;//
private String address;
private String idNumber;
private String department;
private String endDate;
private String birthDay;//生日
--------------
app项目中用 Eventbus 得到 身份证读卡信息。
@Subscribe
public void onEventMainThread(ReadCardEvent readCardEvent) {
isStartMatch = true;
startMatchTime = System.currentTimeMillis();
Log.i(TAG, "检测成功,并且读取到身份证信息");
HSIDCardInfo cardInfo = readCardEvent.getCardInfo();
idCardBean = IdCardConvertUtils.converToIdCardBean(cardInfo);
mPresenter.getRealItemBeanByIdCard(idCardBean);
Log.i("lixiaodaoaaa", "file path is " + FileConstant.ID_CARD_HEAD_FILE_PATH);
Bitmap bitmapFromPath = FileUtils.getBitmapFromPath(FileConstant.ID_CARD_HEAD_FILE_PATH);
ivPeopleHead.setImageBitmap(bitmapFromPath);
}
这个是类型转化类,实现类的转化 读取身份证信息。
/*
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
Author : lixiaodaoaaa
Date : 2019-08-11
Time : 17:13
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
public class IdCardConvertUtils {
public static IdCardBean converToIdCardBean(HSIDCardInfo cardInfo) {
IdCardBean idCardBean = new IdCardBean();
if (null != cardInfo) {
String name = cardInfo.getPeopleName();
String gender = cardInfo.getSex();
String people = cardInfo.getPeople();
String birthDay = DateFormatterUtils.toBirthDay(cardInfo.getBirthDay());
String address = cardInfo.getAddr();
String cardNumber = cardInfo.getIDCard();
String department = cardInfo.getDepartment();
String endDate = cardInfo.getEndDate();
idCardBean.setName(name);
idCardBean.setGender(gender);
idCardBean.setPeople(people);
idCardBean.setBirthDay(birthDay);
idCardBean.setAddress(address);
idCardBean.setIdNumber(cardNumber);
idCardBean.setDepartment(department);
idCardBean.setEndDate(endDate);
return idCardBean;
}
return null;
}
}
Demo下载:联系v : lixiaodaoaaa