Help Center> > SDK Reference >Using Android SDK

Using Android SDK

Users can use SDK in token- or AK/SK-based authentication mode. For details about how to obtain authentication messages, see Authentication. This section describes how to use SDK in token- and AK/SK-based modes.

Download OCR Android SDK from, and decompress it.

A user needs to apply for enabling the service before using it for the first time. For details about how to enable the service, click Subscribe. You only need to subscribe to OCR once.

AK/SK-based Authentication

This section uses ID Card OCR as an example to describe how to use SDK in AK/SK-based authentication mode.

  1. Obtain AK/SK. For details, see Authentication > AK/SK-based Authentication.
  2. Configure AK/SK of the Android SDK.

    Change the values of AK and SK of the akskOcrService function in the file of the demo project to the obtained AK/SK, as shown in Figure 1.

    Figure 1 Modifying the file
  3. If you use a local image file for recognition, modify the Bitmap parameter in the akskOcrService function of the file as highlighted in Figure 2. If you use the default image of the SDK, you do not need to modify the image path.
    Figure 2 Input parameter path
  4. Execute the akskOcrService function. If 200 is displayed on the console, the program is successfully executed. The recognition result can be displayed in the JSON editor, as shown below:
        "result": {
            "name": "李蓝", 
            "sex": "女", 
            "ethnicity": "满", 
            "birth": "1990-01-24", 
            "address": "河北省承德市围场满族蒙古族自治县金车路", 
            "number": "389201199001245580"

    To call other OCR services, change the first parameter of the requestOcrServiceBase64 function to the specific URI. For the URI list, see Mappings Between Services and APIs.

Token-based Authentication

This section uses the ID Card OCR as an example to describe how to use SDK in token-based authentication mode.

  1. Open the file. Change the values of userName, password, and domainName in the tokenOcrService function to the actual username, password, and domain name registered with the system. If the user is not an IAM user, the domain name and username are the same. See Figure 3.
    Figure 3 Changing the username, password, and domain name
  2. Execute the code. The recognition result of ID Card OCR using token-based authentication is displayed.