目录

Preparations

Requesting Permissions

Before using Remote Communication Kit capabilities, check whether you have obtained corresponding permissions for your app. If not, you need to declare these permissions.

Relevant permissions are required for all network requests, except for those for canceling network requests and closing sessions. Specifically, Remote Communication Kit requires the following permissions:

You must manually configure the preceding permissions before using the kit. For details, please refer to the procedure.

[h2]Procedure

Configure the required permissions in the module.json5 file in entry/src/main. The sample code is as follows:

{
  "module": {
    // ...
    "requestPermissions": [
      {
        "name": "ohos.permission.INTERNET"
      },
      {
        "name": "ohos.permission.GET_NETWORK_INFO"
      }
    ],
    "routerMap": "$profile:route_map"
  }
}

Preparations for C API Development

In addition to the aforementioned permission configuration, when using the C API, you also need to set the dynamic library path and header file path in CMakeLists.txt, and then link them.

If the compilation target is entry, add the following commands:

target_include_directories(entry PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/include)
target_link_directories(entry PUBLIC ${HMOS_SDK_NATIVE}/sysroot/usr/lib/aarch64-linux-ohos)
target_link_libraries(entry PUBLIC librcp_c.so) # Link to **librcp_c.so** and other dependent SO files.

HTTP Plaintext Configuration

Starting from version 6.1.0(23), plaintext HTTP interception configuration is supported.

HTTP is a plaintext protocol. To ensure data security, HTTP is typically disabled in favor of HTTPS. You can configure the plaintext HTTP transmission policy in the src/main/resources/base/profile/network_config.json file (create the file if it does not exist). For details about the configuration, please refer to Configuring Plaintext HTTP Access Permissions.

The following configuration example allows plaintext transmission globally except for communication using the domain name example.com. With this configuration, Remote Communication Kit can access this domain name only through HTTPS. If an HTTP request is initiated to this domain name, error code 1007900201 will be reported.

{
  "network-security-config": {
    "base-config": {
      "cleartextTrafficPermitted": true
    },
    "domain-config": [
      {
        "domains": [
          {
            "name": "example.com"
          }
        ],
        "cleartextTrafficPermitted": false
      }
    ],
    "component-config": {
      "Remote Communication Kit": true
    }
  }
}