接口调用流程
1.初始化
- 创建LFLivenessSDK对象detector,具体传参请查看demo
/**
* 获取token
* 强烈建议:appID不要放在客户端
*/
private void requestToken() {
}
- 设置参数,开启人脸识别
/**
* 开始人脸识别
*/
LFLivenessBuilder builder = LivenessBuildUtils.getSettingBuilder(this, HOST + "v2/sdk/liveness_auth", token);
LFLivenessManager.getInstance().startDetect(builder, new LFLivenessListener() {
@Override
public void onDetectFinish(LivenessResult result) {
}
- 业务方根据不同的返回做对应的处理
case LivenessResult.CODE_SUCCESS: //成功
LiveResultUtils.writeResultToFile(result.getFrameArrayList());
Intent intent = new Intent(MainTestActivity.this, NewLFLivenessDetectResultActivity.class);
startActivity(intent);
break;
case LivenessResult.CODE_CANCEL:
String errorMsg = "errorCode=" + result.getErrorCode() + "\nerrorMsg=" + result.getErrorMsg();
LogDebug.e(TAG, errorMsg);
Toast.makeText(MainTestActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
break;
case LivenessResult.CODE_ERROR_ACTIVITY_PAUSE:
showFailDialog(getStringById(R.string.dialog_title_detect_interrupt), null);
break;
case LivenessResult.CODE_ERROR_TIME_OUT:
showFailDialog(getStringById(R.string.dialog_title_detect_timeout), getStringById(R.string.dialog_light_enough));
break;
case LivenessResult.CODE_ERROR_MORE_THAN_ONE_FACE:
showFailDialog(getStringById(R.string.dialog_title_detect_interrupt), getStringById(R.string.dialog_detect_muli_face_tip));
break;
case LivenessResult.CODE_ERROR_NO_FACE:
showFailDialog(getStringById(R.string.dialog_title_detect_interrupt), getStringById(R.string.dialog_detect_face_lose_tip));
break;
default: // 取消
String errorMessage = "errorCode=" + result.getErrorCode() + "\nerrorMsg=" + result.getErrorMsg();
Toast.makeText(MainTestActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
break;
- 请求hack或者认证对比
private void requestHack(byte[] data) {
请求... hack 获取准确的结果
}