首页 Android SDK integration

Android SDK integration

更新时间: 2026-06-29 13:41:22

Enhanced Real-Person Authentication provides an Android client SDK to help you implement real-person authentication features in your app. You can call the server-side authentication initialization API for Enhanced Real-Person Authentication to obtain the unique identifier CertifyId, and then use CertifyId to invoke the Enhanced Real-Person Authentication client SDK. This topic describes the detailed process of integrating the Enhanced Real-Person Authentication SDK into an Android client.

Prerequisites

The SDK requires a phone or tablet running Android 4.0.3 (minSdkVersion ≥ 15) or later.

Note

The SDK does not support emulators or applications running on custom hardware models. To use a custom hardware model, contact your account manager to discuss your use case and evaluate alternative integration solutions.

Permission description

This SDK requires the following permissions to enhance security.

Permission

Required

Notes

android.permission.INTERNET

Yes

The SDK cannot function without this permission.

android.permission.ACCESS_NETWORK_STATE

No (Recommended)

None.

android.permission.CAMERA

Yes

These permissions must be requested at runtime on devices that run Android 6.0 or later.

If you enable these permissions, make sure your app has been granted them before you call the initialization API.

android.permission.READ_EXTERNAL_STORAGE

No (Recommended)

Download and configure the SDK

  1. Download the Enhanced Real-Person Authentication SDK (Android) to your local device and extract the files. The SDK is a standard Android .aar package.

  2. Import all the extracted .aar files into the /libs directory of your app project and add the following dependencies to your app's build.gradle file:

    // SDK modules.
    implementation files('libs/aliyun-identityplatform-xxx.aar')
    implementation files('libs/aliyun-identityocr-xxx.aar')
    implementation files('libs/aliyun-identityface-xxx.aar')
    implementation files('libs/Android-AliyunFaceGuard-xxx.aar')
    implementation files('libs/aliyun-identitycrypto-xxx.aar')
    
    // Third-party SDK dependencies.
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.squareup.okio:okio:1.14.0'
    implementation 'com.aliyun.dpa:oss-android-sdk:2.9.11'
    implementation 'com.alibaba:fastjson:1.2.83_noneautotype'
Note
  • In the dependencies, xxx is a placeholder for the SDK version number.

  • Do not omit the third-party dependency libraries; they are required for the SDK to function correctly.

Function reference

The Enhanced Real-Person Authentication SDK includes three main functions: install for SDK initialization, getMetaInfo for retrieving device information, and faceVerify for starting the authentication process. The following sections provide detailed descriptions of these functions.

Initialize the SDK (install function)

  • Description:

    Call this function to initialize the SDK. You can configure delayed initialization so that the SDK for facial recognition scenarios is initialized only after the user accepts the Privacy Policy.

  • Function prototype:

    public void install(Context context);
  • Parameters:

    Name

    Type

    Description

    context

    Context

    The application context.

  • Return value:

    None.

getMetaInfo function

  • Description:

    Call this function to retrieve the environment context of the mobile device and send the information to the App Server.

    The App Server uses this information as the MetaInfo parameter to call the InitSmartVerify API. This call returns a CertifyId for subsequent validation.

  • Function prototype:

    String metaInfo = IdentityPlatform.getInstance().getMetaInfo(MainActivity.this);
  • Parameters:

    Name

    Type

    Description

    context

    Context

    The context of the current activity.

  • Return value:

    Returns the environment context of the mobile device in JSON format. The following code shows a sample return value:

    {
        "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 (faceVerify)

  • Description:

    Call this function to start the Enhanced Real-Person Authentication process.

  • Function prototype:

    public void faceVerify(String certifyId, Map<String, String> extParams, 
                            IdentityCallback callback);
  • Parameters:

    Parameter

    Type

    Description

    certifyId

    String

    The CertifyId obtained from the server-side authentication initialization API (InitSmartVerify).

    Note

    Each CertifyId is valid for only one call to the faceVerify function. You must obtain a new CertifyId before each call to the faceVerify function.

    extParams

    Map<String, String>

    Optional custom parameters. For a list of supported custom fields, see extParams.

    callback

    IdentityCallback

    The callback for the authentication result. The callback format is as follows:

    public class IdentityResponse {
        // The result code. For more information, see the "Return Codes" section.
        public int code;
        
        // A description of the result code.
        public String message;
    }
    
    public interface IdentityCallback {
        boolean response(IdentityResponse response);
    }

    The following table describes the custom fields supported by the extParams parameter.

    Parameter

    Description

    Example

    kIdentityParamKeyIdCardFaceOnly

    Specifies whether to scan only the portrait side of the ID card. Valid values:

    • YES: Recognizes only the portrait side of the ID card.

    • NO: Recognizes both the portrait side and the national emblem side of an ID card.

    NO

    kIdentityParamKeyNextButtonColor

    The background color of the button at the bottom of the OCR result confirmation page.

    #FF0000

    kIdentityParamKeyShowResult

    Whether to display the OCROCR recognition result confirmation page。Valid values:

    • YES:Display the OCROCR recognition result confirmation page。

    • NO:Do not display the OCROCR recognition result confirmation page。

    YES

    kIdentityParamKeyValidIdCardDate

    Specifies whether to validate the expiration date of the ID card. Valid values:

    • YES: Verify the ID card expiration date.

    • NO: Does not verify the validity period of the ID card.

    Note

    This parameter takes effect when kIdentityParamKeyIdCardFaceOnly is set to NO.

    NO

    kIdentityParamKeyWaterMark

    Custom watermark text on document images. The default text is "For business use only".

    For business use only

    kIdentityParamKeyShowAlbumIcon

    Specifies whether to display the feature for selecting an image from the album. Valid values are YES and NO.

    YES

    kIdentityParamKeyRoundProgressColor

    In the circular face scanning frame mode, this parameter specifies a custom color for the progress bar.

    #FF6A00

  • Return value:

    None.

Return values

The server returns the validation result in the IdentityResponse.code parameter. The following table describes the possible values.

Code

Description

1000

Authentication successful.

1001

Authentication failed.

1002

System error.

1003

SDK initialization failed. Confirm that the client time is correct. If the system time on the mobile phone is modified, the Alibaba Cloud gateway validation fails.

1004

Camera error.

1005

Network error.

1006

User canceled.

1007

The CertifyId is invalid.

1009

Client timestamp error.

1010

The SDK was not initialized before validation.

1011

Operation timed out.

1012

Android 4.3 and earlier versions are not supported.

1013

Camera permission is not enabled.

Sample code

public class MainActivity extends AppCompatActivity {
    
    private String certifyId = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize the SDK. We recommend waiting about 3 seconds after calling install before calling other verification APIs.
        IdentityPlatform.getInstance().install(MainActivity.this);
        
        // Get the MetaInfo.
        String metaInfo = IdentityPlatform.getMetaInfo(MainActivity.this);
        
        // Send the MetaInfo to your app server to call the server-side InitSmartVerify API and get the CertifyId.
        // certifyId = getCertifyIdFromServer(metaInfo);
        
        // Start the verification.
        IdentityPlatform.getInstance().faceVerify(certifyId, null,
          new IdentityCallback() {
            @Override
            public boolean response(final IdentityResponse response) {
                if (IdentityResponseCode.IDENTITY_SUCCESS == response.code) {
                    Toast.makeText(MainActivity.this,
                                   "Authentication passed", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this,
                                   "Authentication failed([" + response.code + "]" + response.message + ")",
                                   Toast.LENGTH_LONG).show();
                }
                return true;
            }
        });
    }
}

API obfuscation configuration

To prevent issues from API obfuscation when building a release package, add the following rules to your ProGuard configuration.

-verbose
-keep class com.aliyun.identity.face.** {*;}
-keep class com.aliyun.identity.ocr.** {*;}
-keep class com.aliyun.identity.platform.** {*;}
-keep class com.ant.phone.xmedia.algorithm.** {*;}
-keep class com.alipay.zoloz.** {*;}
-keep class net.security.device.api.** {*;}

-keep class com.darsh.multipleimageselect.** { *; }
-dontwarn com.darsh.multipleimageselect.**

-keep class com.soundcloud.android.crop.** { *; }
-dontwarn com.soundcloud.android.crop.**
-keep class com.aliyun.identity.IdentityUtils {*;}

Demo package

Enhanced Liveness Verification Demo (Android)

阿里云首页 实人认证 相关技术圈