赞
踩
1.创建应用 获取应用的API Key和Secret Key
2.下载SDK,将SDK的jar包和依赖包导入自己的项目。
3.下载License文件
4.初始化
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initAccessTokenWithAkSk();
} else {
Toast.makeText(getApplicationContext(), "需要android.permission.READ_PHONE_STATE", Toast.LENGTH_LONG).show();
}
}
private boolean checkTokenStatus() {
if (!hasGotToken) {
Toast.makeText(getApplicationContext(), "token还未成功获取", Toast.LENGTH_LONG).show();
}
return hasGotToken;
}
/**
* 以license文件方式初始化
*/
private void initAccessToken() {
OCR.getInstance(this).initAccessToken(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken accessToken) {
String token = accessToken.getAccessToken();
hasGotToken = true;
}
@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "licence方式获取token失败", Toast.LENGTH_SHORT).show();
}
});
}
}, getApplicationContext());
}
/**
* 用明文ak,sk初始化
*/
private void initAccessTokenWithAkSk() {
OCR.getInstance(this).initAccessTokenWithAkSk(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken result) {
String token = result.getAccessToken();
hasGotToken = true;
}
@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "AK,SK方式获取token失败", Toast.LENGTH_SHORT).show();
}
});
}
}, getApplicationContext(), "xxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxx");
}
/**
* 自定义license的文件路径和文件名称,以license文件方式初始化
*/
private void initAccessTokenLicenseFile() {
OCR.getInstance(this).initAccessToken(new OnResultListener<AccessToken>() {
@Override
public void onResult(AccessToken accessToken) {
String token = accessToken.getAccessToken();
hasGotToken = true;
}
@Override
public void onError(OCRError error) {
error.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MyZiliaoActivity.this, "自定义文件路径licence方式获取token失败", Toast.LENGTH_SHORT).show();
}
});
}
}, "aip.license", getApplicationContext());
}
}
身份证正面Intent intent = new Intent(MyZiliaoActi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。