Android 集成阿里云 人脸识别
Android集成官方文档:https://help.aliyun.com/document_detail/127598.html?spm=a2c4g.11186623.6.564.583c5f3e1BgoXP
集成步骤:
1,申请相关账号,并且将项目签名打包成apk上传后下载相应的sdk;(注意,为了方便测试 最好debug包 和release包通用一个签名文件)
signingConfigs {
def alias = "key"
def password = "you password"
def filePath = "D://xx/MLKey.jks"
debug {
keyAlias alias
keyPassword password
storeFile file(filePath)
storePassword(password)
}
release {
keyAlias alias
keyPassword password
storeFile file(filePath)
storePassword(password)
}
}
2,下载的sdk里包括一张验证图片,放置于项目res->drawble文件夹下 ;
3,将下载文件里的AAR文件复制到工程JNILib目录,如果项目本身集成有okhttp等,不要复制过来
其中fastjson也必须要(毕竟阿里亲儿子),windvane为webview 文件,必须要;
4,so文件复制到jniLibs文件夹,根据自己项目情况选择对应cpu架构;
5,app gradle文件设置()
android{
...
}
repositories {
flatDir {
dirs 'libs'
//如果集成aar文件放置于子moudle 此处可以设置成 dirs '../yourModleName/libs'
}
}
dependencies {
...
implementation(name: 'rpsdk-4.0.4', ext: 'aar')
implementation(name: 'oss-android-sdk-2.9.2', ext: 'aar')
implementation(name: 'SecurityGuardSDK-external-release-5.4.193-preInstall', ext: 'aar')
implementation(name: 'SecurityBodySDK-external-release-5.4.112-preInstall', ext: 'aar')
implementation files('libs/fastjson-1.2.62.jar')
implementation files('libs/windvane-min-8.0.3.2.3.jar')
}
6,调用
Apllication文件初始化:
@Override
public void onCreate() {
super.onCreate();
initAliFace();
}
private void initAliFace() {
/**
* 通过ALBiometricsConfig 自定义您的UI
*/
ALBiometricsConfig.Builder alBiometricsConfig = new ALBiometricsConfig.Builder();
alBiometricsConfig.setNeedSound(false);//默认是否开启声音
alBiometricsConfig.transitionMode = TransitionMode.BOTTOM;//从下弹出
CloudRealIdentityTrigger.initialize(this, true, alBiometricsConfig.build());//第二个参数是本地日志能力(若打开 会记录问题到本地,方便后期排查线上用户问题)
}
activity问调用(首先申请相机权限,这里的token是后台上传识别图片去阿里服务器后,回调获得的)
private void openVerify(){
CloudRealIdentityTrigger.startVerifyByNative(this, token, getALRealIdentityCallback());
}
/**
* 基础回调的方式 TODO
*
* @return
*/
private ALRealIdentityCallback getALRealIdentityCallback() {
return (alRealIdentityResult, s) -> {
//DO your things
LogUtils.debugInfo("RPSDK", "ALRealIdentityResult:" +
alRealIdentityResult.audit);
if (alRealIdentityResult.audit == 1) { //识别成功,是要对比的图片
userInfo.setCertification("2");
mPresenter.updateSelfInfo(userInfo);
} else {//识别失败
userInfo.setCertification("-1");
mPresenter.updateSelfInfo(userInfo);
}
};
}
AndroidManifest.xml
<manifest>
...
<application>
...
<!-- 阿里云识别 -->
<activity
android:name="com.alibaba.security.biometrics.activity.ALBMiometricActivtiy"
android:hardwareAccelerated="true"
/>
<activity android:name="com.alibaba.security.rp.activity.RPTakePhotoActivity"
android:screenOrientation="portrait"
/>
<activity android:name="com.amap.api.navi.AmapRouteActivity"/>
<activity android:name="com.alibaba.security.rp.activity.RPH5Activity"
android:screenOrientation="portrait"
/>
</application>
</manifest>
--------------------------------------------------------------------------------完成分割线--------------------------------------------------------------------------
总结:
如果遇到没有错误的闪退,解决方法 :1.加上AndroidManifest的acitivity声明
2.如果不行 降低gradle版本
#Fri Apr 03 17:37:12 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.3.1'
...
}
...
}
————————————————
版权声明:本文为CSDN博主「SmallWalnutBG」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/SmallWalnutBG/article/details/106321283
网友评论