| | |
| | | import com.dayu.recharge.utils.DeviceNumberUtils; |
| | | import com.dayu.recharge.utils.SocketUtil; |
| | | import com.dayu.recharge.utils.TipUtil; |
| | | import com.dayu.recharge.utils.ToastUtil; |
| | | import com.dayu.recharge.view.ProgressDialog; |
| | | import com.kernal.passportreader.sdk.CardsCameraActivity; |
| | | import com.kernal.passportreader.sdk.utils.DefaultPicSavePath; |
| | | import com.kernal.passportreader.sdk.utils.ManageIDCardRecogResult; |
| | | import com.permissionx.guolindev.PermissionX; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | import kernal.idcard.android.ResultMessage; |
| | | import kernal.idcard.camera.CardOcrRecogConfigure; |
| | | import kernal.idcard.camera.SharedPreferencesHelper; |
| | | |
| | | /** |
| | | * Copyright (C), 2023, |
| | |
| | | |
| | | |
| | | private void startCamera() { |
| | | Intent intent = new Intent(NewCardActivity.this, CameraActivity.class); |
| | | intent.putExtra("typeFront", 1); |
| | | CardOcrRecogConfigure.getInstance() |
| | | .initLanguage(getApplicationContext()) |
| | | .setSaveCut(true) |
| | | .setOpenIDCopyFuction(true) |
| | | .setnMainId(getSharedPreferencesStoreMainId()) |
| | | .setnSubID(getSharedPreferencesStoreSubId()) |
| | | .setFlag(0) |
| | | .setnCropType(0) |
| | | .setSavePath(new DefaultPicSavePath(this, true)); |
| | | Intent intent = new Intent(this, CardsCameraActivity.class); |
| | | startActivityForResult(intent, SCAN_IDCARD_REQUEST); |
| | | } |
| | | |
| | | private int defValueMainId = 2; |
| | | private int defValueSubId = 0; |
| | | |
| | | public int getSharedPreferencesStoreMainId() { |
| | | return SharedPreferencesHelper.getInt( |
| | | getApplicationContext(), "nMainId", defValueMainId); |
| | | } |
| | | |
| | | public int getSharedPreferencesStoreSubId() { |
| | | return SharedPreferencesHelper.getInt( |
| | | getApplicationContext(), "nSubID", defValueSubId); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (resultCode == RESULT_OK) { |
| | | switch (requestCode) { |
| | | case SCAN_IDCARD_REQUEST: |
| | | String result = data.getStringExtra("OCRResult"); |
| | | try { |
| | | JSONObject jo = new JSONObject(result); |
| | | |
| | | // sb.append(String.format("正面 = %s\n", jo.opt("type"))); |
| | | // sb.append(String.format("姓名 = %s\n", jo.opt("name"))); |
| | | // sb.append(String.format("性别 = %s\n", jo.opt("sex"))); |
| | | // sb.append(String.format("民族 = %s\n", jo.opt("folk"))); |
| | | // sb.append(String.format("日期 = %s\n", jo.opt("birt"))); |
| | | // sb.append(String.format("号码 = %s\n", jo.opt("num"))); |
| | | // sb.append(String.format("住址 = %s\n", jo.opt("addr"))); |
| | | // sb.append(String.format("签发机关 = %s\n", jo.opt("issue"))); |
| | | // sb.append(String.format("有效期限 = %s\n", jo.opt("valid"))); |
| | | // sb.append(String.format("整体照片 = %s\n", jo.opt("imgPath"))); |
| | | // sb.append(String.format("头像路径 = %s\n", jo.opt("headPath"))); |
| | | |
| | | String name = jo.getJSONObject("Name").opt("value").toString(); |
| | | String idNumber = jo.getJSONObject("Num").opt("value").toString(); |
| | | this.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | newCardBinding.newCardName.setText(name); |
| | | newCardBinding.newCardId.setText(idNumber); |
| | | //跳转扫描界面识别完成之后,数据回传 |
| | | if (data != null) { |
| | | //数据回传的获取 |
| | | Bundle bundle = data.getBundleExtra("resultbundle"); |
| | | //bundle不为null,代表这识别成功 |
| | | if (bundle != null) { |
| | | ResultMessage resultMessage = (ResultMessage) bundle.getSerializable("resultMessage"); |
| | | newCardBinding.newCardName.setText(resultMessage.GetRecogResult[1]); |
| | | newCardBinding.newCardId.setText(resultMessage.GetRecogResult[6]); |
| | | newCardBinding.newCardIdTip.setVisibility(View.VISIBLE); |
| | | } else { |
| | | String error = data.getStringExtra("error"); |
| | | String StrPath = data.getStringExtra("strpicpath"); |
| | | ToastUtil.show(error); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } catch (JSONException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 进入相机界面扫描成功之后的调用 |
| | | */ |
| | | private void CameraScanSuccess(Bundle bundle) { |
| | | ResultMessage resultMessage = (ResultMessage) bundle.getSerializable("resultMessage"); |
| | | String[] picPath = bundle.getStringArray("picpath"); |
| | | //数据的封装 |
| | | String result = ManageIDCardRecogResult.managerSucessRecogResult(resultMessage, getApplicationContext()); |
| | | try { |
| | | /** |
| | | * @param recogResult 识别结果 |
| | | * @param picPath 图片路径数组,picPath[0]: 全图路径;picPath[1]: 裁切图;picPath[2]: 证件头像 |
| | | */ |
| | | // Intent intent = new Intent(this, ShowResultActivity.class); |
| | | // intent.putExtra("recogResult", result); |
| | | // intent.putExtra("fullPagePath", picPath[0]); |
| | | // intent.putExtra("cutPagePath", picPath[1]); |
| | | // startActivity(intent); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | private void setData() { |
| | | |
| | | try { |