你的打赏,是对我最大的支持:
银行卡 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_BANK_CARD);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
驾驶证 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_GENERAL);
startActivityForResult(intent, REQUEST_CODE_DRIVING_LICENSE);
行驶证 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_GENERAL);
startActivityForResult(intent, REQUEST_CODE_VEHICLE_LICENSE);
身份证正面(手动识别) 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
身份证反面(手动识别) 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
身份证正面(自动识别) 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE, true);
intent.putExtra(CameraActivity.KEY_NATIVE_MANUAL, true);
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
身份证反面(自动识别) 调用:
intent = new Intent(MainActivity.this, CameraActivity.class);
intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH, FileUtil.getSaveFile(getApplication()).getAbsolutePath());
intent.putExtra(CameraActivity.KEY_NATIVE_ENABLE, true);
intent.putExtra(CameraActivity.KEY_NATIVE_MANUAL, true);
intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
主页权限判断 :
主要事相机的权限:
<uses-permission android:name="android.permission.CAMERA" />
关键代码:
/**
* 判断相关权限问题
*/
public void checkPermission() {
// int checkINSTALL = ActivityCompat.checkSelfPermission(this, android.Manifest.permission.REQUEST_INSTALL_PACKAGES);
int checkSelfPermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (checkSelfPermission == PackageManager.PERMISSION_GRANTED) { //允许 0, 询问 -1
//已经获取到权限 获取用户媒体资源
// checkUpdate();
} else {
//没有拿到权限 是否需要在第二次请求权限的情况下
// 先自定义弹框说明 同意后在请求系统权限(就是是否需要自定义DialogActivity)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1514);
}
}
private void initAccessTokenWithAkSk() {
OCR.getInstance().initAccessTokenWithAkSk(
new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken result) {
// 本地自动识别需要初始化
initLicense();
Log.d("MainActivity", "onResult: " + result.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "初始化认证成功", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onError(OCRError error) {
error.printStackTrace();
Log.e("MainActivity", "onError: " + error.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "初始化认证失败,请检查 key", Toast.LENGTH_SHORT).show();
}
});
}
}, getApplicationContext(),
// 需要自己配置 https://console.bce.baidu.com
"**************************************",//填写自己的
// 需要自己配置 https://console.bce.baidu.com
"***************************************");//填写自己的
}
private void initLicense() {
CameraNativeHelper.init(this, OCR.getInstance().getLicense(),
new CameraNativeHelper.CameraNativeInitCallback() {
@Override
public void onError(int errorCode, Throwable e) {
final String msg;
switch (errorCode) {
case CameraView.NATIVE_SOLOAD_FAIL:
msg = "加载so失败,请确保apk中存在ui部分的so";
break;
case CameraView.NATIVE_AUTH_FAIL:
msg = "授权本地质量控制token获取失败";
break;
case CameraView.NATIVE_INIT_FAIL:
msg = "本地质量控制";
break;
default:
msg = String.valueOf(errorCode);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,
"本地质量控制初始化错误,错误原因: " + msg, Toast.LENGTH_SHORT).show();
}
});
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_CAMERA && resultCode == Activity.RESULT_OK) {
if (data != null) {
String contentType = data.getStringExtra(CameraActivity.KEY_CONTENT_TYPE);
String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
if (!TextUtils.isEmpty(contentType)) {
if (CameraActivity.CONTENT_TYPE_ID_CARD_FRONT.equals(contentType)) {
recIDCard(IDCardParams.ID_CARD_SIDE_FRONT, filePath);
} else if (CameraActivity.CONTENT_TYPE_ID_CARD_BACK.equals(contentType)) {
recIDCard(IDCardParams.ID_CARD_SIDE_BACK, filePath);
} else if (CameraActivity.CONTENT_TYPE_BANK_CARD.equals(contentType)) {
recCreditCard(filePath);
}
}
}
}
if (requestCode == REQUEST_CODE_DRIVING_LICENSE && resultCode == Activity.RESULT_OK) {
String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
recDrivingCard(filePath);
}
if (requestCode == REQUEST_CODE_VEHICLE_LICENSE && resultCode == Activity.RESULT_OK) {
String filePath = FileUtil.getSaveFile(getApplicationContext()).getAbsolutePath();
recVehicleCard(filePath);
}
}
地址:https://console.bce.baidu.com
可以查看 应用详情 查看文档 下载SDK: