tencent cloud

Android SDK Log Upload
Last updated: 2025-11-07 17:40:38
Android SDK Log Upload
Last updated: 2025-11-07 17:40:38
This article introduces how to quickly get started with the Android SDK of Cloud Log Service to implement log upload operation.

Prerequisites

Create and obtain TencentCloud API key information secretId and secretKey. For key information acquisition, please visit API Key Management.
Please ensure the associated account has appropriate SDK log upload permission.
Installed Android development environment.

Installing the Android SDK

1. Create an Android project.
2. In the dependencies block of the build.gradle file under the corresponding module of the Android Studio project, add the following dependencies (build.gradle is usually under the APP directory).
implementation(group: 'com.tencentcloudapi.cls', name: 'tencentcloud-cls-sdk-android', version: '1.0.13')

Request Parameters

Variable
Type
Required
Description
endpoint
String
Yes
Regional information. For completion, refer to the domain name in the Log upload via API Tab under available region.
secretId
String
Yes
TencentCloud API key information. For key information acquisition, please visit API key management. Please ensure the associated account has appropriate SDK log upload permission.
secretKey
String
Yes
TencentCloud API key information. For key information acquisition, please visit API key management. Please ensure the associated account has appropriate SDK log upload permission.
topicId
String
Yes
Log topic ID info.

Upload Example Code for Logs

In your Android project, you can use the following example code to implement log upload. The example code is as follows.
It is not recommended to store TencentCloud API key information in plaintext in project code. You can dynamically obtain API key information through environment variables. For details, see configure environment variables.
public static void main(String[] args) {
String endpoint = "ap-xxxxxx.cls.tencentcs.com";
// API key secretId, required.
String secretId = "";
// API key secretKey, required.
String secretKey = "";
// Log topic ID, required.
String topicId = "";
// NetworkUtils.getLocalMachineIP() retrieves the local network interface ip. If not specified, it populates by default with the network outbound ip received by the server.
final AsyncProducerConfig config = new AsyncProducerConfig(endpoint, secretId, secretKey, "", NetworkUtils.getLocalMachineIP());

// Build a client instance.
final AsyncProducerClient client = new AsyncProducerClient(config);

for (int i = 0; i < 10000; ++i) {
List<LogItem> logItems = new ArrayList<>();
int ts = (int) (System.currentTimeMillis() / 1000);
LogItem logItem = new LogItem(ts);
logItem.PushBack(new LogContent("__CONTENT__", "hello world"));
logItem.PushBack(new LogContent("city", "xxxxxxx"));
logItem.PushBack(new LogContent("logNo", Integer.toString(i)));
logItem.PushBack(new LogContent("__PKG_LOGID__", (String.valueOf(System.currentTimeMillis()))));
logItems.add(logItem);
client.putLogs(topicId, logItems, result -> System.out.println(result.toString()));
}
client.close();
}

Conclusions

Through these steps, you can quickly use the Android SDK of Tencent Cloud CLS to complete log upload. If you encounter any issues, please contact us to get help.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback