LTS Android SDK
If you need to collect and analyze user information on Android, such as browser, browsing behavior, device, device exception, and network usage records, you can use this SDK to report logs to LTS in Kotlin and Java.

This function is available for whitelisted users in regions CN North-Beijing4, CN East-Shanghai1, and CN South-Guangzhou. To use it, create a service ticket.
Transport Protocol
HTTPS
Prerequisites
- You have obtained the name of the region where LTS is deployed.
- You have obtained a project ID of your Huawei Cloud account. For details, see API Credentials.
- You have obtained the IDs of the target log group and log stream in LTS.
Version Updates
Version |
Download Address |
Verification File Download Address |
Description |
System |
---|---|---|---|---|
1.0.28 |
Resolved the conflict caused by project configuration since version 1.0.26. |
Android 7 or later |
||
0.0.5 |
Maven Central |
- |
Retained the functions in version 1.0.28 and added support for Kotlin 1.3.x. |
Android 7 or later |
1.0.27 |
Optimized the cache efficiency. |
Android 7 or later |
||
0.0.4 |
Maven Central |
- |
Retained the functions in version 1.0.27 and added support for Kotlin 1.3.x. |
Android 7 or later |
1.0.26 |
Fixed the data exception issue caused by asynchronous modification of input parameters. |
Android 7 or later |
||
1.0.25 |
Enhanced code robustness and added parameter protection. |
Android 7 or later |
||
1.0.24 |
|
Android 7 or later |
||
1.0.21 |
Discarded the setconfig method and replaced it with LTS SDK's construction method. |
Android 7 or later |
||
1.0.19 |
|
Android 7 or later |
||
1.0.18 |
|
Android 7 or later |
||
1.0.17 |
This is the first release. Four interfaces are provided: init, config, report, and reportImmediately. |
Android 7 or later |
Installing the Android SDK
- Integrate the access SDK.
- Integration using the Maven repository
- Add dependencies to build.gradle.
plugins { ... id 'org.jetbrains.kotlin.android' version 'KOTLIN_VERSION' apply false // Add kotlin 1.6.20 or later for 1.x.x and 1.3.61 or later for 0.0.x. ... }
- Add dependencies to app/build.gradle.
dependencies { ... implementation 'io.github.lts-sdk:lts-sdk-android:1.0.28' ... }
- Add the Maven repository to settings.gradle.
pluginManagement{ ... repositories { ... // Add the following content: mavenCentral() } } dependencyResolutionManagement { ... repositories { ... // Add the following content: mavenCentral() } }
- Add dependencies to build.gradle.
- Manual integration
- Download the LTS SDK package.
- Decompress the package to a specific directory.
- Add the decompressed AAR static library file to your project.
- Add dependencies to build.gradle.
plugins { ... id 'org.jetbrains.kotlin.android' version 'KOTLIN_VERSION' apply false // Add kotlin 1.6.20 or later for 1.x.x and 1.3.61 or later for 0.0.x. ... }
- Add dependencies to app/build.gradle.
dependencies { ... implementation fileTree(dir: $dir, include: ['*.aar']) // Enter the folder where the .aar package is located, for example, libs. implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0' // 0.0.x depends on 1.3.3. implementation 'androidx.core:core-ktx:1.7.0'// 0.0.x depends on 1.2.0. implementation 'com.google.code.gson:gson:2.8.9' kapt 'androidx.room:room-compiler:2.3.0' // 0.0.x depends on 2.2.6. api 'androidx.room:room-runtime:2.3.0' // 0.0.x depends on 2.2.6. api 'androidx.room:room-common:2.3.0' // 0.0.x depends on 2.2.6. ... }
- Add the Maven repository to settings.gradle.
If your Gradle version is earlier than 7.0, add the Maven repository to the build.gradle file.
pluginManagement{ ... repositories { ... // Add the following content: google() mavenCentral() } } dependencyResolutionManagement { ... repositories { ... // Add the following content: google() mavenCentral() } }
- Integration using the Maven repository
- Perform initialization. For details about the parameters, see Table 4.
- Add dependencies.
import com.cloud.lts.UserConfig import com.cloud.lts.LTSSDK
- Kotlin: example initialization code
// Note: Hard-coded or plaintext AK and SK of the account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. val ak: String = getData("HUAWEICLOUD_SDK_AK") val sk: String = getData("HUAWEICLOUD_SDK_SK") // LTS parameter configuration val userConfig = UserConfig.Builder() // Mandatory parameters .setRegion(USER_REGION) // Region of LTS .setProjectId(PROJECT_ID) // Project ID of the account .setGroupId(LOG_GROUP_ID) // LTS log group ID .setStreamId(LOG_STREAM_ID) // LTS log stream ID .setAccessKey(ak) // Access key .setSecretKey(sk) // Secret access key // Optional parameters .setUrlHost(url) // LTS public network domain name .setCacheThreshold(200) .setTimeInterval(60) .setIsReportBackground(true) .setIsReportLaunch(false) .build() // LTS initialization method ltssdk = LTSSDK( </* Application Instance */> , userConfig)
- Java: example initialization code. The LTS SDK supports multi-instance log reporting. Instances are created based on different configurations for reporting.
// Note: Hard-coded or plaintext AK and SK of the account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. String ak = getData("HUAWEICLOUD_SDK_AK") String sk = getData("HUAWEICLOUD_SDK_SK") // LTS parameter configuration UserConfig userConfig = new UserConfig.Builder() // Mandatory parameters .setRegion(USER_REGION) // Region of LTS .setProjectId(PROJECT_ID) // Project ID of the account .setGroupId(LOG_GROUP_ID) // LTS log group ID .setStreamId(LOG_STREAM_ID) // LTS log stream ID .setAccessKey(ak) // Access key .setSecretKey(sk) // Secret access key // Optional parameters .setUrlHost(url) // LTS public network domain name .setCacheThreshold(200) .setTimeInterval(60) .setIsReportBackground(true) .setIsReportLaunch(false) .build(); // LTS initialization method ltssdk = new LTSSDK( </* Application Instance */> , userConfig);
- Add dependencies.
- Report logs. LTS provides two log reporting methods.
Table 2 Log reporting methods Method
Description
report(content, labels)
LTS stores logs in the local database and reports them in real time based on the configured policy.
reportImmediately(content, labels)
Report logs immediately.
Table 3 Parameters Name
Description
content
Log content. The value can be a dictionary or dictionary array. A maximum of 300 key-value pairs are supported. The maximum length of the JSON string converted from content is 30 × 1024. If the length exceeds the limit, the excess part will be truncated.
labels
Log labels.
- The value can be a dictionary or null.
- Maximum number of outermost key-value pairs: 50.
- Maximum length of the outermost key: 64.
- The value can contain letters, digits, and underscores (_), and must start with a letter.
- The maximum length of a dictionary converted to a JSON string is 30,720 characters. If the length exceeds 30,720 characters, the log cannot be reported.
- Kotlin sample code:
var ltssdk: LTSSDK val food = hashMapOf(Pair("food_1", "rice"), Pair("food_2", "wheat"), Pair("food_3", "egg")) val fruit = hashMapOf(Pair("fruit_1", "apple"), Pair("fruit_2", "pear"), Pair("fruit_3", "banana")) val label = hashMapOf( Pair("date","2023-10-01")) val contents = listOf(food, fruit).toTypedArray() ltssdk.report(food, label) // Cache and report a single record, with labels ltssdk.report<String, String>(food) // Cache and report a single record, without labels ltssdk.reportImmediately(food, label) // Immediately report a single record, with labels ltssdk.reportImmediately<String, String>(food) // Immediately report a single record, without labels ltssdk.report(contents, label) // Cache and report multiple records, with labels ltssdk.report<String, String>(contents) // Cache and report multiple records, without labels ltssdk.reportImmediately(contents , label) // Immediately report multiple records, with labels ltssdk.reportImmediately<String, String>(contents) // Immediately report multiple records, without labels
- Java sample code:
LTSSDK ltssdk; HashMap fruit = new HashMap<String, String>(){{ put("fruit_1", "apple"); put("fruit_2", "pear"); put("fruit_3", "banana"); }}; HashMap food = new HashMap<String, String>(){{ put("food_1", "rice"); put("food_2", "wheat"); put("food_3", "egg"); }}; HashMap<String, String> labels = new HashMap(){{ put("date","2023-10-01"); }}; HashMap[] contents = {food, fruit}; ltssdk.report(food); // Cache and report a single record, without labels ltssdk.report(food, labels); // Cache and report a single record, with labels ltssdk.reportImmediately(food); // Immediately report a single record, without labels ltssdk.reportImmediately(food, labels); // Immediately report a single record, with labels ltssdk.report(contents); // Cache and report multiple records, without labels ltssdk.report(contents, labels); // Cache and report multiple records, with labels ltssdk.reportImmediately(contents); // Immediately report multiple records, without labels ltssdk.reportImmediately(contents , labels); // Immediately report multiple records, with labels
Parameters
Parameter |
Type |
Mandatory |
Default Value |
Description |
---|---|---|---|---|
projectId |
String |
Yes |
- |
Project ID of the account. |
accessKey |
String |
Yes |
- |
AK of the account. Hard-coded or plaintext AK and SK of the account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. |
secretKey |
String |
Yes |
- |
SK of the account. Note: Hard-coded or plaintext AK and SK of the Huawei Cloud account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. |
region |
String |
Yes |
- |
Region of LTS. |
groupId |
String |
Yes |
- |
LTS log group ID. |
streamId |
String |
Yes |
- |
LTS log stream ID. |
url |
String |
No |
null |
Public network domain name for reporting. If it is not set, a link is automatically generated based on the region. The format is as follows: https://lts-access.{region}.myhuaweicloud.com. |
cacheThreshold |
Long |
No |
200 |
When the number of logs stored in the local database reaches this threshold, an alarm is reported. Value range: 30 to 1000. |
timeInterval |
Long |
No |
3 |
Interval for triggering reporting. Value range: 1 to 1800, in seconds. |
isReportBackground |
Boolean |
No |
true |
Whether to report logs when the app switches to running in the background. |
isReportLaunch |
Boolean |
No |
false |
Whether to report logs upon app startups. |
Log Reporting Policies
This SDK supports the following log reporting policies: threshold-based reporting, scheduled reporting, reporting when the app is switched to the background, and reporting upon startup. Set parameters such as cacheThreshold, timeInterval, isReportBackground, and isReportLaunch based on the scenario.
Configuring Permissions
The LTS SDK requires the network permission of Android. If this permission is not configured, add the following content to the Manifest.xml file of the app:
manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> ... // Add the following content: <uses-permission android:name="android.permission.INTERNET" /> ... </manifest>
Obfuscation Configuration
To achieve code obfuscation, add the following code segment to the obfuscation configuration file:
-keep class com.cloud.**{*;}
Debugging
Enable debugging if needed. Then you can monitor log reporting in real time on the console, and make adjustments accordingly.
Call the static method of the LTS SDK to make adjustments. The SDK supports five log levels: Debug, Info, Warning, Error, and Off. The default log level is Off. The five levels correspond to the following parameters: LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARNING, LogLevel.ERROR, and LogLevel.OFF. The following is a code example:
LTSSDK.setLogLevel(LogLevel.DEBUG)
Obtaining Parameters
- Regions
Table 5 Regions Name
Region
CN North-Beijing4
cn-north-4
CN East-Shanghai1
cn-east-3
CN South-Guangzhou
cn-south-1
- To obtain a log group's ID, choose Log Management in the navigation pane of the LTS console and hover over the target log group's name.
- To obtain a log stream's ID, click the down arrow on the left of the corresponding log group name to expand the log stream list, then hover over the target log stream's name.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot