This document explains how to integrate the ID Verification SDK for Android and provides code examples.
Limitations
The SDK supports mobile devices (phones or tablets) running Android 4.3 (API level 18) or later. The x86 architecture is not supported.
Permissions
The SDK requires the following permissions:
|
Permission |
Required |
Description |
|
android.permission.INTERNET |
Yes |
Required for the SDK to connect to the internet. |
|
android.permission.ACCESS_NETWORK_STATE |
No (Recommended) |
|
|
android.permission.CAMERA |
Yes |
Camera-related permissions. This is a runtime permission on Android 6.0 (API level 23) and later. |
|
android.permission.READ_PHONE_STATE |
No (Recommended) |
|
|
android.permission.READ_EXTERNAL_STORAGE |
No (Recommended) |
Download and configure the SDK
-
Download the Android-CardVerifySDK. The SDK is a standard Android Archive (AAR) file.
-
After downloading, unzip the package. Copy all AAR files from the Android SDK folder to your project's
libsdirectory. Then, add the following dependencies to your module-levelbuild.gradlefile.
// SDK modules
implementation files('libs/aliyun-identitybase-meta-sdk-xxx.aar')
implementation files('libs/aliyun-identityocrservice-meta-sdk-xxx.aar')
implementation files('libs/aliyun-identitycrypto-meta-sdk-1.0.0.aar')
implementation files('libs/aliyun-identityplatform-meta-sdk-1.0.0.aar')
implementation files('libs/aliyun-identityocr-meta-sdk-xxx.aar')
implementation files('libs/aliyun-identitymnn-meta-sdk-xxx.aar')
// SDK third-party dependency modules
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okio:okio:2.2.2'
implementation 'com.aliyun.dpa:oss-android-sdk:2.9.4'
implementation 'com.alibaba:fastjson:1.1.72.android'
-
In the dependencies,
xxxrepresents the specific version number of the SDK. -
Do not omit any third-party dependencies, as doing so will cause the SDK to malfunction.
API reference
The Android SDK provides methods for initialization (install), metainfo retrieval (getMetaInfo), and verification (verify).
Initialize the SDK (install)
-
Method signature:
public void install(Context context); -
Parameters:
Parameter
Type
Description
context
Context
The context of the current application.
Get metainfo (getMetaInfo)
-
Method signature:
public static String getMetaInfo(Context context); -
Parameters:
Parameter
Type
Description
context
Context
The context of the current application.
-
Return value: A string in JSON format that contains information about the mobile device's environment.
{ "apdidToken": "", "appName": "com.aliyun.identity.platform", "appVersion": "1.0.1", "bioMetaInfo": "5.1.0:11501568,4", "deviceBrand": "xxx", "deviceManufacturer": "xxx", "deviceModel": "xxx", "deviceType": "android", "identityVer": "1.0.0", "osVersion": "10", "sdkVersion": "1.0.9" }
Start verification (verify)
-
Before calling this method, pass the metainfo to your server and obtain a
certifyIdby calling the server-side InitCardVerify API. -
The
certifyIdobtained from the server corresponds to thetransactionIdparameter of theverifymethod.
-
Method signature:
public void verify(String transactionId, Map<String, String> extParams, IdentityCallback callback); -
Parameters:
Parameter
Type
Description
transactionId
String
The
certifyIdobtained from the server-side initialization API (InitCardVerify).ImportantEach
transactionIdis valid for a single call to theverifymethod. You must obtain a newtransactionIdfor each verification attempt.extParams
Map<String, String>
Optional parameters. In most cases, you can pass
null.For details on the supported custom fields, see the
extParamsconfiguration table below.callback
IdentityCallback
A callback interface for the verification result. For details about the return codes in the callback, see the IdentityResponse.code table.
public class IdentityResponse { // See the "IdentityResponse.code table" for details. public int code; // A description of the return code. public String message; } public interface IdentityCallback { boolean response(IdentityResponse response); } -
extParamsconfiguration:Key
Description
Example (String)
IdentityParams.OcrResultButtonColor
The color of the button on the OCR result page.
#FF0000
IdentityParams.RoundProgressColor
The color of the circle during the face scan.
#FF0000
IdentityParams.ShowBlbumIcon
Specifies whether to display the album upload entry during the document OCR step:
-
1: Display (default)
-
0: Do not display
1
IdentityParams.CardOcrTimeOutPeriod
The timeout period for the OCR step.
The value must be between 20 and 60 seconds. The default is 20 seconds.
20
IdentityParams.SdkLanguage
The SDK supports the following languages by default:
-
zh-Hans: Simplified Chinese -
zh-Hant: Traditional Chinese -
en: English -
ja: Japanese -
ko: Korean -
id: Indonesian -
ms: Malay -
th: Thai -
vi: Vietnamese
NoteIn addition to the default languages, the SDK also supports custom languages. For more information, see Add a language.
zh-Hans
CloseButtonLayout
The position of the close button:
-
left: On the left (default)
-
right: On the right
left
-
-
IdentityResponse.code table:
Return code
Billed
Description
1000
Yes
The user completed the verification process, and the recommended result is Pass. This result is for reference only. Call the server-side CheckResult API to get the definitive verification result.
1001
Yes
The user completed the verification process, and the recommended result is Fail. This result is for reference only. Call the server-side CheckResult API to get the definitive verification result and the detailed reason for failure.
1002
No
System error.
1003
No
SDK initialization failed. Check if the client's system time is correct.
1004
No
Camera permission error. Try the following steps to resolve this issue:
-
Ensure your app has been granted camera permission before starting the verification.
-
If the permission error persists after authorization, try clearing the app's cache and retrying.
1005
No
Network error.
1006
No
User canceled the process.
1007
No
Invalid
transactionId.1009
No
Client timestamp error.
1011
No
Incorrect document type submitted.
1012
No
Key information is missing from the recognized document, or format validation failed.
1013
No
Poor image quality.
1014
No
The number of attempts exceeded the limit.
1015
No
The Android system version is too low.
1016
No
Camera permission not granted.
-
Add a language
To add a custom language:
-
Open your app project (the module that integrates the ID Verification SDK).
-
In your app project, create a resource directory for the target language and a
strings.xmlfile within it. For example, to add Russian, create avalues-ru-rRUdirectory under the main module and add thestrings.xmlfile to it.
values
values-de-rDE
values-fr-rFR
values-ru-rRU
strings.xml
AndroidManifest.xml
-
Translate the string values in the
strings.xmlfile into the target language. Refer to the template in Appendix 1 and replace the Chinese text with the target language. -
In your code, specify the custom language in the "language-country" format. For example, to set the language to Russian:
Map<String,String> extParams = new HashMap<>();
extParams.put(IdentityParams.SdkLanguage,"ru-RU");
IdentityPlatform.getInstance().verify(transactionId, extParams, new IdentityCallback() {
@Override
public boolean response(final IdentityResponse response) {
if (IdentityResponseCode.IDENTITY_SUCCESS == response.code) {
Toast.makeText( context: MainActivity.this,
text: "Verify Success.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText( context: MainActivity.this,
text: "Verify Failed. [" + response.code + "]" + response.message + ")",
Toast.LENGTH_LONG).show();
}
return true;
}
});
Sample code
public class MainActivity extends AppCompatActivity {
private String transactionId = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the SDK
IdentityPlatform.getInstance().install(MainActivity.this);
// Get metainfo
String metaInfo = IdentityPlatform.getMetaInfo(MainActivity.this);
/**
* Send metainfo to your app server. Then, call the server-side InitCardVerify API to obtain the transactionId.
*/
// transactionId = getTransactionIdFromServer(metaInfo);
// Set the SDK language
Map<String, String> extParams = new HashMap<>();
extParams.put(IdentityParams.SdkLanguage, "en");
// Start verification
IdentityPlatform.getInstance().verify(transactionId, extParams,
new IdentityCallback() {
@Override
public boolean response(final IdentityResponse response) {
if (IdentityResponseCode.IDENTITY_SUCCESS == response.code) {
Toast.makeText(MainActivity.this,
"Verification passed", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this,
"Verification failed([" + response.code + "]" +
response.message + ")",
Toast.LENGTH_LONG).show();
}
return true;
}
});
}
}
Obfuscation configuration
-verbose
-keep class com.aliyun.identity.platform.api.** {*;}
-keep class com.aliyun.identity.IdentityUtils {*;}
-keep class com.aliyun.identity.ocr.IdentityOcrApi {*;}
-keep class com.aliyun.identity.platform.model.** {*;}
-keep class com.aliyun.identity.platform.config.** {*;}
-keep class com.aliyun.meta.verify.service.algorithm.** {*;}
-keep class com.aliyun.meta.verify.base.algorithm.** {*;}
-keep class com.aliyun.meta.verify.service.ocr.IdentityDocService {*;}
-keep class com.alibaba.fastjson.** {*;}
-keep class com.aliyun.identity.platform.log.** {*;}// Obfuscation for the log module, optional
Demo package
Download AliyunIdcardVerifyDemo.zip to try out the demo.