serverParamInfo. The SDK decrypts and applies these parameters internally, and the frontend no longer hardcodes them.OcrCloudStatus.SUCCESS), and the business party pulls the structured result from its own server using the sdkToken.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 |
public static OcrOverseasCloudKit getInstance()
public void init(Context context)
startCloudOcr. Otherwise, startCloudOcr returns errorCode=-1 and errorMsg="Please call init() before startCloudOcr" through the IOcrCloudResultListener#onFailed callback.Parameter Type | Parameter Name | Parameter Description |
Context | context | Application context information |
public void updateConfig(OcrSDKConfig config)
startCloudOcr automatically builds and applies the underlying OcrSDKConfig based on serverParamInfo.Parameter Type | Parameter Name | Parameter Description |
OcrSDKConfig | config | New underlying SDK configuration object |
public void startCloudOcr(Activity activity,OcrCloudConfig config,IOcrCloudResultListener listener)
sdkToken / serverParamInfo is not empty.serverParamInfo and parse the server-delivered parameters for this task, including ocrModeType / cardSide / nationality / cardType / maxImageSize / allowUploadPhoto / cardAlgorithmConfig.cardSide. Double-sided capture is enabled when the value is BOTH.application/octet-stream) to /ocr/v1/ocr/recognize.OcrCloudStatus.SUCCESS is returned through the IOcrCloudResultListener#onSuccess callback. If any step fails, a structured OcrCloudError is returned through the onFailed callback.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 |
public void release()
getInstance() creates a new instance, which requires calling init() again.public String getCurrentToken()
OcrCloudConfig. If no call has been initiated, an empty string is returned.public String createMetaData()
public String getVersion()
public void setCloudEventListener(IOcrCloudEventListener listener)
startCloudOcr.Parameter Type | Parameter Name | Parameter Description |
listener | Collection event listener. Pass null to unregister it. |
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.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 |
/*** 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);}
/*** 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);}
onSuccess, the business party should use result.getSdkToken() to pull the final structured recognition result from the cloud on its own server.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 |
Type | Term | Description | Default Value |
String | sdkToken | sdkToken Passed Through to the Caller | Null |
int | errorCode | -1 | |
String | errorMsg | Error Message | null |
OcrCloudStatus Value | Description |
SUCCESS | Recognition completed, and the backend has generated the final result. |
LanguageStyle Type | Description |
AUTO | Follow system language |
ENGLISH | English |
SIMPLIFIED_CHINESE | Simplified Chinese |
TRADITIONAL_CHINESE | Traditional Chinese |
BAHASA | Indonesian |
CUSTOMIZE_LANGUAGE | Custom language |
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 |
sequenceDiagramparticipant App as Business Appparticipant Backend as Business Backendparticipant SDK as OcrOverseasCloudKitparticipant Cloud as OCR CloudApp->>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.
// 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() {@Overridepublic void onMainViewCreate(View mainView) {// The main View is created. You can add custom views here.}@Overridepublic void onMainViewDestroy() {// The main View is destroyed.}@Overridepublic void onEventParamMap(HashMap<String, Object> map) {// Pass through parameters}});// Step 5: Start recognition.OcrOverseasCloudKit.getInstance().startCloudOcr(activity, config,new IOcrCloudResultListener() {@Overridepublic 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.}}@Overridepublic 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();
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. |
resultCode is "300102"), the SDK passes through the original value as errorCode. For its semantics, refer to the server-side agreement.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.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.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.release() is called, the singleton is set to null. To use it again, you must call getInstance() and then init().errorCode=300102 and errorMsg="net connect timeout" through the onFailed callback.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback