Updated on 2023-03-16 GMT+08:00

Installing the APK

Function Description

  • API name

    InstallApk

  • Function

    This API is used to install the APK on a cloud phone. The system downloads the specified APK file and installs it on the cloud phone.

    A single APK application or multiple APK applications can be installed. You can run the install command to install a single APK. Only one APK can be installed at a time. You can run the install-multiple command to install multiple APKs (a single APK is split into multiple APKs). Only multiple APKs of the same application can be installed at a time.

    This API is an asynchronous API. You can call APIs in Querying the Task Execution Status and Querying the Task Execution Status List to query the task execution result.

  • Notes

    You have granted the read-only permissions on the OBS bucket to the Cloud Phone service system account. For details, see Managing Cloud Phones in Batches in the Cloud Phone User Guide.

    The management plane performance is limited. Executing ADB commands in batches on the same server blocks the execution of other tasks on the cloud phone. You are advised to install the APK by developing an app store. The maximum size of an APK that can be installed is 2 GB. That is, an APK larger than 2 GB in the OBS bucket cannot be installed on a cloud phone. If the size of an APK exceeds 2 GB, an error is returned.

URI

POST /v1/{project_id}/cloud-phone/phones/commands

For details, see Table 1.
Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

For details about how to obtain the project ID, see Obtaining a Project ID.

Request

  • Request parameters

    Parameter

    Mandatory

    Type

    Description

    command

    Yes

    String

    Specifies the ADB command. If a single APK is installed, set this parameter to install. If multiple APKs are installed, set this parameter to install-multiple.

    content

    Yes

    String

    Specifies the APK file in the specified OBS bucket. (The APK file must be uploaded to the specified bucket in advance.)

    Only letters, digits, underscores (_), periods (.), slashes (/), colons (:), and hyphens (-) are allowed. Only .apk files can be pushed.

    File format: obs://obs-bucket-name/obs-file-path/file.apk

    In the single-APK scenario, only one APK can be transferred, and the maximum length is 1,024 bytes. In the multi-APK scenario, a maximum of 50 APKs separated by spaces can be transferred, and the maximum length is 8,100 bytes.

    server_ids

    No

    Array of strings

    Specifies the ID list of the cloud phone servers.

    This parameter is mandatory when phone_ids does not need to be configured.

    Obtain it by referring to Querying Cloud Phone Servers.

    phone_ids

    No

    Array of strings

    Specifies the cloud phone ID list.

    This parameter is mandatory when server_ids does not need to be configured.

    Obtain it by referring to Querying Cloud Phones.

  • Example request for installing a single APK
    POST https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones/commands
    {
        "command": "install",
        "content": "-t -r obs://push-bucket/my_apps/test.apk",
        "phone_ids": [
            "1234567b8bab40ffb711234cb80d0234",
            "1678567b8bab40f93711234cb80d0764"
        ]
    }
  • Example request for installing multiple APKs
    POST https://{CPH Endpoint}/v1/{project_id}/cloud-phone/phones/commands
    {
        "command": "install-multiple",
        "content": "-t -r obs://push-bucket/my_apps/test_part1.apk obs://push-bucket/my_apps/test_part_2.apk obs://push-bucket/my_apps/test_part3.apk",
        "phone_ids": [
            "1234567b8bab40ffb711234cb80d0234",
            "1678567b8bab40f93711234cb80d0764"
        ]
    }

Response

  • Response parameters

    Parameter

    Type

    Description

    request_id

    String

    Specifies the request ID, which is unique.

    jobs

    Array of objects

    Specifies the task information. For details, see Table 2.

    Table 2 Data structure description of job

    Parameter

    Type

    Description

    phone_id

    String

    Specifies the unique ID of a cloud phone. This parameter is contained in tasks related to cloud phones.

    job_id

    String

    Specifies the unique ID of a task.

  • Example response
    {
        "request_id": "6837531fd3f54550927b930180a706bf",
        "jobs": [
            {
                "phone_id": "1234567b8bab40ffb711234cb80d0234",
                "job_id": "1564567b8bab40f34711234cb80d0123"
            },
            {
                "phone_id": "1678567b8bab40f93711234cb80d0764",
                "job_id": "1564567b8bab40f34711234cb80d5678"
            }
        ]
    }

Returned Values

See Returned Values.

Error Codes

See Error Codes.