tencent cloud

eKYC

Android API Overview

Download
Focus Mode
Font Size
Last updated: 2026-10-27 14:31:48
AI-Translated & Reviewed

In Token mode (one-stop public cloud access), the main classes involved in the Android OCR SDK include OcrOverseasCloudKit, OcrCloudConfig, IOcrCloudResultListener, OcrCloudResult, OcrCloudError, OcrCloudStatus, LanguageStyle, and CustomConfigUi. The APIs supported by these classes are described in detail below.
Note:
Differences from the "full-process access (OcrSDKKit)" mode:
The business party only needs to store the sdkToken and no longer holds or issues temporary keys (SecretId / SecretKey / Token).
Business-side parameters such as the certificate type, the mode for capturing certificate photos, and whether album upload is allowed are all delivered by the backend through serverParamInfo. The SDK decrypts and applies these parameters internally, and the frontend no longer hardcodes them.
The SDK no longer returns the recognition JSON to the caller. Instead, it only returns the "recognition complete" status (OcrCloudStatus.SUCCESS), and the business party pulls the structured result from its own server using the sdkToken.

OcrOverseasCloudKit

OcrOverseasCloudKit is the external API class for public cloud OCR in Token mode, and all Token mode features are centralized in this class.
API
Capability Description
Creating a Singleton of OcrOverseasCloudKit
Initializing the SDK
Refreshing/Updating SDK Configuration Information
Starting public cloud OCR recognition (completing capture + upload in a single call).
Actively Releasing Resources
Obtaining the Currently Cached sdkToken
Synchronously collect and encrypt device/application metadata, which needs to be uploaded to the server when a token is obtained.
Obtaining the Current SDK Version
Registering a Collection Event Listener

getInstance()

public static OcrOverseasCloudKit getInstance()

Description: Create a singleton instance of OcrOverseasCloudKit.
Return value: The singleton instance of OcrOverseasCloudKit.


init()

public void init(Context context)

Description: Initialize the SDK. It must be called once before startCloudOcr. Otherwise, startCloudOcr returns errorCode=-1 and errorMsg="Please call init() before startCloudOcr" through the IOcrCloudResultListener#onFailed callback.
Input parameters:
Parameter Type
Parameter Name
Parameter Description
Context
context
Application context information

updateConfig()

public void updateConfig(OcrSDKConfig config)

Description: Actively overwrite the underlying SDK configuration after the SDK has been initialized. Generally, you do not need to call this method because startCloudOcr automatically builds and applies the underlying OcrSDKConfig based on serverParamInfo.
Input parameters:
Parameter Type
Parameter Name
Parameter Description
OcrSDKConfig
config
New underlying SDK configuration object

startCloudOcr()

public void startCloudOcr(Activity activity,
OcrCloudConfig config,
IOcrCloudResultListener listener)

Description: Starts public cloud OCR recognition. The SDK performs the following process internally without requiring awareness from the business party:
1. Verify that sdkToken / serverParamInfo is not empty.
2. Decrypt serverParamInfo and parse the server-delivered parameters for this task, including ocrModeType / cardSide / nationality / cardType / maxImageSize / allowUploadPhoto / cardAlgorithmConfig.
3. Automatically select "single-sided capture" or "double-sided capture" based on cardSide. Double-sided capture is enabled when the value is BOTH.
4. After capture is complete, upload the jpg image as encrypted binary data (application/octet-stream) to /ocr/v1/ocr/recognize.
5. After the upload succeeds and the backend response is parsed, OcrCloudStatus.SUCCESS is returned through the IOcrCloudResultListener#onSuccess callback. If any step fails, a structured OcrCloudError is returned through the onFailed callback.

Input parameters:
Parameter Type
Parameter Name
Parameter Description
Activity
activity
Current Activity object that launches the default OCR page
config
Startup configuration in Token mode (including sdkToken and serverParamInfo)
listener
Callback object for receiving recognition status/errors

release()

public void release()

Description: Actively releases resources. Call this method when exiting a business page or when resources need to be cleaned up. After release is called, the singleton is set to null. The next call to getInstance() creates a new instance, which requires calling init() again.


getCurrentToken()

public String getCurrentToken()

Description: Obtains the currently cached sdkToken.
Return value: the sdkToken in the current OcrCloudConfig. If no call has been initiated, an empty string is returned.


createMetaData()

public String createMetaData()

Description: Synchronously collects metadata of the current device or application and encrypts it using the SDK's built-in algorithm, making it easier for the business party to submit the metadata when the business party exchanges for or queries the sdkToken from its own backend.


getVersion()

public String getVersion()

Description: Obtains the current SDK version.
Return value: the current SDK version information.


setCloudEventListener()

public void setCloudEventListener(IOcrCloudEventListener listener)

Description: Registers a capture event listener to monitor UI lifecycle and parameter passthrough events during OCR capture. It can be called before startCloudOcr.
Input parameters:
Parameter Type
Parameter Name
Parameter Description
listener
Collection event listener. Pass null to unregister it.
Attention:
This interface is independent of OcrEventListener in full-process mode. It exposes only three callbacks: onMainViewCreate / onMainViewDestroy / onEventParamMap, and does not expose internal events such as camera events. The onCameraOpenSuccess callback is handled internally by the SDK, including Turing Shield and other logic, and is not forwarded externally.

OcrCloudConfig

OcrCloudConfig is the startup configuration entity class that needs to be passed in when OCR is started in Token mode. It uses javabean setter methods for parameter configuration.
Type
Term
Description
Default Value
String
sdkToken
Required. SDK business token, obtained by the business party backend through a cloud API call, serving as the unique identifier for this recognition request.
Empty (required; if not passed, the callback fails directly)
String
serverParamInfo
Required. Encrypted parameter string obtained by the business party backend and passed through to the SDK. After decryption inside the SDK, it is used to drive this capture and recognition.
Empty (required; if not passed, the callback fails directly)
customConfigUi
Custom UI configuration
null
languageStyle
Language used
LanguageStyle.AUTO
String
languageCode
Extended multilingual language code (used with CUSTOMIZE_LANGUAGE)
Null
boolean
showBestImgConfirmDialog
Whether to show the best frame confirmation dialog
false
boolean
useSystemClip
Whether to use system cropping
false
boolean
openClipImage
Whether to enable the capture feature when an image is selected
true
boolean
disableSystemRecordScreen
Whether to disable screen recording/screenshot (enable FLAG_SECURE)
false
boolean
openLog
Whether to enable logging
true
boolean
showPrivacyPolicyDialog
Whether to show the privacy policy dialog
true

IOcrCloudEventListener

An event callback interface for the public cloud OCR capture process, used to monitor UI lifecycle and parameter passthrough events during capture.
/**
* Event callback interface for the public cloud OCR capture process
*/
public interface IOcrCloudEventListener {

/**
* Callback for when the main View for OCR recognition is created
*
* @param mainView The main View
*/
void onMainViewCreate(View mainView);

/**
* Callback for when the page is recycled
*/
void onMainViewDestroy();

/**
* Pass through additional parameters
*
* @param map Parameters to pass through
*/
void onEventParamMap(HashMap<String, Object> map);
}


IOcrCloudResultListener

A callback class for public cloud OCR recognition results, used to receive recognition status and error exceptions.
/**
* Callback interface for public cloud OCR recognition results
*/
public interface IOcrCloudResultListener {

/**
* Success callback for recognition
*
* @param result The success result, which contains the sdkToken and status.
*/
void onSuccess(OcrCloudResult result);

/**
* Failure callback for recognition
*
* @param error The failure result, which contains the sdkToken, error code (int), and error message.
*/
void onFailed(OcrCloudError error);
}
Note:
In Token mode, the SDK does not return the structured OCR recognition JSON. After receiving onSuccess, the business party should use result.getSdkToken() to pull the final structured recognition result from the cloud on its own server.


OcrCloudResult

Data carried in the success callback.
Type
Term
Description
Default Value
String
sdkToken
sdkToken Passed Through to the Caller
Null
status
Recognition status (currently only SUCCESS, indicating that the backend has returned a result)
null

OcrCloudError

Data carried in the failure callback.

Type
Term
Description
Default Value
String
sdkToken
sdkToken Passed Through to the Caller
Null
int
errorCode
Error code (int type; for details, see the Error code section)
-1
String
errorMsg
Error Message
null

OcrCloudStatus

Enumeration of recognition states.

OcrCloudStatus Value
Description
SUCCESS
Recognition completed, and the backend has generated the final result.

LanguageStyle

LanguageStyle is an enum that lists the supported language types.

LanguageStyle Type
Description
AUTO
Follow system language
ENGLISH
English
SIMPLIFIED_CHINESE
Simplified Chinese
TRADITIONAL_CHINESE
Traditional Chinese
BAHASA
Indonesian
CUSTOMIZE_LANGUAGE
Custom language

CustomConfigUi

The configuration class for custom UI is shared with the "full-process integration" mode. Common properties are listed below and can be set through javabean setters. For complete fields, see the SDK header file.

Type
Term
Description
boolean
isShowTitleBar
Set whether to show the title bar of the default page.
String
titleBarText
Set the text displayed in the title bar.
int
titleColor
Set the title bar background color (0xFFFFFF format).
int
cardFrameColor
Set the color of the card preview frame corners when they are selected.
int
imageSelectResId
Icon resource id of the gallery selection button on the default page
int
lightImageOnResId
Icon resource id for turning on the flash
int
lightImageOffResId
Icon resource id for turning off the flash
int
takePicturesResId
Icon resource id of the active photo capture button
int
backActionIconResId
Icon resource id of the back button
boolean
isRemoveAlbum
Whether to hide the album selection button (Note: When the server delivers allowUploadPhoto=false, the SDK automatically sets it to true, overriding the value passed by the business party)
boolean
isRemoveFlash
Whether to hide the flash button
boolean
isLandscape
Landscape or not
boolean
isShowTips
Display the tips box or not
String
showTipsText
Text content of the tips box
int
portraitLayoutResId
Resource id of the custom portrait layout
int
landscapeLayoutResId
Resource id of the custom landscape layout
boolean
showCustomPermissionDialog
Whether to show the custom permission dialog
String
customPermissionDialogTitle
Title of the custom permission dialog
String
customPermissionDialogDetail
Details of the custom permission dialog


Access Process

sequenceDiagram
participant App as Business App
participant Backend as Business Backend
participant SDK as OcrOverseasCloudKit
participant Cloud as OCR Cloud

App->>SDK: getInstance().init(context)
App->>SDK: Calls createMetaData() to obtain metadata.
SDK-->>App: Returns the metaData.
App->>Backend: Uploads metaData and requests sdkToken / serverParamInfo.
Backend-->>App: Delivers sdkToken + serverParamInfo.
App->>SDK: startCloudOcr(activity, OcrCloudConfig, listener)
SDK->>SDK: Decrypts serverParamInfo and determines single-sided or double-sided capture.
SDK->>SDK: Starts camera capture and obtains the optimal jpg frame.
SDK->>Cloud: POSTs the optimal OCR frame for recognition.
Cloud-->>SDK: Sends the recognition completion response.
SDK-->>App: onSuccess(OcrCloudResult{status=SUCCESS, sdkToken})
App->>Backend: Pulls structured recognition results using sdkToken.


Access Example

// Step 1: Initialize in the onCreate method of the Application or business page (only once).
OcrOverseasCloudKit.getInstance().init(getApplicationContext());

// Step 2: Before requesting the sdkToken or serverParamInfo from the business backend,
// First, use createMetaData() to synchronously collect device and application metadata (encrypted inside the SDK), and submit it together with the application request.
// This field remains consistent with the server-side protocol so that the backend can pass it through when calling the cloud CreateOCRToken API for risk control and parameter validation.
String metaData = OcrOverseasCloudKit.getInstance().createMetaData();
// TODO: Submit metaData as a request parameter (for example, with the field name metaData) to the business backend. For more information, see app-public.
// Implementation of TokenApiHelper#applyToken: body.put("metaData", OcrOverseasCloudKit.getInstance().createMetaData())

// Step 3: Obtain the sdkToken / serverParamInfo from the business backend.
String sdkToken = "..."; // Issued by the business backend.
String serverParamInfo = "..."; // Issued by the business backend as an encrypted string.

// Step 4: Construct the startup configuration.
OcrCloudConfig config = new OcrCloudConfig();
config.setSdkToken(sdkToken);
config.setServerParamInfo(serverParamInfo);
config.setLanguageStyle(LanguageStyle.SIMPLIFIED_CHINESE);
config.setShowPrivacyPolicyDialog(true);
// Optional: Customize the UI.
CustomConfigUi customConfigUi = new CustomConfigUi();
customConfigUi.setShowTitleBar(true);
customConfigUi.setTitleBarText("ID Card Recognition");
config.setCustomConfigUi(customConfigUi);

// Optional: Register a capture event listener.
OcrOverseasCloudKit.getInstance().setCloudEventListener(new IOcrCloudEventListener() {
@Override
public void onMainViewCreate(View mainView) {
// The main View is created. You can add custom views here.
}

@Override
public void onMainViewDestroy() {
// The main View is destroyed.
}

@Override
public void onEventParamMap(HashMap<String, Object> map) {
// Pass through parameters
}
});

// Step 5: Start recognition.
OcrOverseasCloudKit.getInstance().startCloudOcr(activity, config,
new IOcrCloudResultListener() {
@Override
public void onSuccess(OcrCloudResult result) {
// Recognition is complete. The business party can use result.getSdkToken() to pull structured results on the server.
if (result.getStatus() == OcrCloudStatus.SUCCESS) {
String token = result.getSdkToken();
// TODO: Notify the business backend to pull the recognition result.
}
}

@Override
public void onFailed(OcrCloudError error) {
// Error handling: error.getErrorCode() / error.getErrorMsg()
}
});

// Step 5: Release resources at an appropriate time (for example, in the onDestroy method of the business page).
OcrOverseasCloudKit.getInstance().release();


Error Code

OcrCloudError#errorCode is of the int type and is uniformly mapped by the SDK from string error codes. For the implementation, see OcrSdkNetSender#mapErrorCodeToInt. Common error codes are as follows:
Error Code
Constant Name
Description
-1
-
Parameter validation failure (such as sdkToken/serverParamInfo is empty, Activity is empty, init() not called first, and so on).
100100
TXY_SDK_PARAMETER_ERROR_CODE
Parameter exception
100102
TXY_SDK_NETWORK_ERROR_CODE
Network exception.
100103
TXY_SDK_CAMERA_PERMISSION_ERROR_CODE
Camera permission exception.
200101
TXY_SDK_USER_CANCEL_CODE
The user actively cancels the recognition.
300101
TXY_SDK_VERIFY_MODEL_INIT_FAIL
Model/SDK initialization exception.
300102
TXY_SDK_VERIFY_SERVER_FAIL
Service parsing exception (including network timeout, ciphertext parsing failure, and unknown error fallback).
300103
TXY_SDK_API_SIGNATURE_FAIL
Signature failure.
300104
TXY_SDK_CAMERA_ERROR_CODE
Camera exception.
300105
TXY_SDK_YTCONFIG_INIT_ERROR_CODE
Initialization configuration failure.
300106
TXY_SDK_OCR_IMAGE_NULL
Image is abnormally empty.
300107
TXY_SDK_OCR_AUTH_FAIL
license authorization failure
300108
TXY_SDK_SYSTEM_VERSION_LOW
System version is too low.
300109
TXY_SDK_AUTO_MODE_TIME_OUT
Automatic mode timeout (no image captured).
300110
TXY_SDK_INNER_SDK_OCR_ERROR
SDK internal error.
300111
TXY_SDK_INNER_SDK_OCR_ERROR_CLIP_ERROR
SDK internal image cropping exception.
300112
TXY_SDK_OCR_ERROR_CARD_TYPE_ERROR
Document type mismatch.
300113
TXY_SDK_OCR_WARN_ERROR_MANY_TIME
OCR failure: too many alarms.
Error Code
Description
400100
Alarm Code for triggering specified interception.
400101
Document type mismatch (the provided document type does not match the specified type).
400102
Document side mismatch (the provided document side differs from the selected side).
400103
Document proportion too small (the document occupies too small a proportion of the photo).
400104
Multiple documents detected.
400105
OCR recognition failure.
400106
Document information verification failed.
400107
Input parameter error.
400108
Internal service error.
400109
Service not activated / Account overdue payment / Resource bundle exhausted.
400110
Request frequency exceeds limit (rate limiting triggered).
400111
Invalid image dimensions or file size.
400112
File parsing failure.
Note:
If the business API directly returns a pure numeric string (for example, the server resultCode is "300102"), the SDK passes through the original value as errorCode. For its semantics, refer to the server-side agreement.

Must-Knows

1. You must call init() before startCloudOcr(). init performs the underlying SDK initialization and tracking initialization internally. The native library YTImageRefinerPub is loaded when getInstance() creates the singleton. If you call the startup API without initialization, onFailed returns errorCode=-1 and a description.
2. sdkToken and serverParamInfo must be issued by the business backend. The frontend should not parse or reuse serverParamInfo on its own. It is recommended to obtain new values from the backend each time the service is started to avoid using expired data.
3. Do not mix OcrOverseasCloudKit with OcrSDKKit. Token mode and full-process mode have different network protocols and callback semantics, so choose only one of them within the same business process.
4. After release() is called, the singleton is set to null. To use it again, you must call getInstance() and then init().
5. The default network timeout is 60s. After a timeout, the SDK proactively stops the current request and returns errorCode=300102 and errorMsg="net connect timeout" through the onFailed callback.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback