Quick start

BLS

  • Function Release Records
  • Product Description
    • Usage restrictions
    • Product Introduction
  • Product pricing
  • Quick Start
    • Introduction
    • Install agent
    • Create LogStore
    • Create Transmission Task
    • Log Analysis and Alerting
    • Create Delivery Task
  • Operation guide
    • Baidu Intelligent Cloud Environment Preparation
    • Overview
    • Identity and access management
    • Logset Management
    • Agent
      • Install Agent on Host
      • Install Agent in K8s Environment
      • Agent Management
      • Agent Release Version
      • Set Agent Startup Parameters
    • Log Collection
      • Transmission Task Collection
        • Create Transmission Task
        • Manage Transmission Task
      • Uploading Logs Using Kafka Protocol
    • Query analysis
      • Log query
      • SQL Syntax
      • Search Syntax
    • Dashboard
      • Overview
      • Management Dashboard
      • Management Dashboard Charts
    • Alarm management
      • Alert Overview
      • Alarm strategy
        • Management alarm strategy
        • Trigger conditions
      • Alarm history
      • Alert execution statistics
      • Alarm notification
        • Alarm Notification Template
        • Alarm callback
    • Data processing
      • Log Delivery
        • Log Delivery Overview
        • Create Delivery Task
        • Manage Delivery Task
      • Scheduled SQL Analysis
        • Manage Scheduled SQL Analysis Task
        • Create Scheduled SQL Analysis Task
      • Real-Time Consumption
      • Data processing
        • Data processing
          • Overview of data processing functions
          • Process control function
          • Mapping enrichment functions
          • Event operation functions
          • Field operation functions
          • Field value extraction functions
    • Log Applications
      • Intelligent Diagnostics
  • Best Practices
    • Use Year-Over-Year and Month-Over-Month as Alert Trigger Conditions
    • BLS Integration with Kibana
    • Use BLS via Grafana
  • Development Guide
    • API Reference
      • API function release records
      • API Overview
      • Interface Overview
      • General Description
      • Service domain
      • Common error codes
      • Terminology
      • Project Related APIs
        • Create Project
        • Update Project
        • Describe Project
        • Delete Project
        • List Project
      • LogStore Related APIs
        • Create LogStore
        • Update LogStore
        • Delete LogStore
        • Describe LogStore
        • Batch Get LogStore
        • List LogStore
      • LogStream Related APIs
        • List LogStream
      • LogRecord Related APIs
        • Push log PushLogRecord
        • Obtain logrecord PullLogRecord
        • Search analysis log QueryLogRecord
        • Histogram API QueryLogHistogram
      • Fast Query FastQuery Related Interfaces
        • Create Fast Query CreateFastQuery
        • Update Fast Query UpdateFastQuery
        • Delete Fast Query DeleteFastQuery
        • Get Fast Query Details DescribeFastQuery
        • Get Fast Query List ListFastQuery
      • Index Related APIs
        • Create Index
        • Update Index
        • Delete Index
        • Describe Index
      • Log Shipper LogShipper Related Interfaces
        • Create Log Shipper
        • Update Log Shipper
        • Set Single Log Shipper Status
        • Delete Single Log Shipper
        • Bulk Delete Log Shipper
        • List Log Shipper Records
        • List Log Shipper
        • Bulk Set Log Shipper Status
        • Get Log Shipper
      • Alarm-Related Interfaces
        • CreateAlarmPolicy
        • UpdateAlarmPolicy
        • DeleteAlarmPolicy
        • ValidateAlarmCondition
        • ValidateAlarmPolicySQL
        • EnableAlarmPolicy
        • DescribeAlarmRecord
        • DisableAlarmPolicy
        • DescribeAlarmPolicy
        • ListAlarmPolicy
        • ListAlarmRecord
        • ListAlarmExecutionStats
        • ListAlarmExecutions
      • LogStore Template-Related Interfaces
        • CreateLogStoreTemplate
        • UpdateLogStoreTemplate
        • DeleteLogStoreTemplates
        • DescribeLogStoreTemplates
        • DescribeLogStoreTemplate
      • Download Log Download Related Interfaces
        • Create Download Task CreateDownloadTask
        • Get Download Task List ListDownloadTask
        • Delete Download Task DeleteDownloadTask
        • Get Download Task Address GetDownloadTaskLink
        • Get Download Task Details DescribeDownloadTask
      • LogAlarm Related Interfaces
        • SetLogAlarmStatus
        • deleteLogAlarm
        • createLogAlarm
        • listLogAlarm
        • updateLogAlarm
        • BulkDeleteLogAlarm
        • PreviewAlarmLogRecord
        • getLogAlarm
        • BulkSetLogAlarmStatus
      • Transmission Task Related Interfaces
        • Create Task CreateTask
        • UpdateTask
      • Interfaces Compatible with Elasticsearch
        • ResolveIndex
        • FieldCaps
        • TermsEnum
        • AsyncSearch
    • SDK Reference
      • Go SDK
        • Overview
        • Initialization
        • Version Release Records
        • Project Operations
        • LogStore Operations
        • Install the SDK Package
        • LogStream Operations
        • LogRecord Operations
        • FastQuery Operations
        • LogShipper Operations
        • Index Operations
        • Download Task Operations
      • Java SDK
        • Overview
        • Install the SDK Package
        • LogRecord Operations
      • iOS SDK
        • Overview
        • Quick start
        • Version Release Records
      • Android SDK
        • Overview
        • Quick start
        • Version Release Records
      • Android & iOS SDK Download
      • SDK Privacy Policy
      • SDK Developer Personal Information Protection Compliance Guide
    • Importing SLS Collection Configuration
  • FAQs
    • Common Questions Overview
    • Fault-related questions
    • Configuration-related questions
  • Log Service Level Agreement SLA
All documents
menu
No results found, please re-enter

BLS

  • Function Release Records
  • Product Description
    • Usage restrictions
    • Product Introduction
  • Product pricing
  • Quick Start
    • Introduction
    • Install agent
    • Create LogStore
    • Create Transmission Task
    • Log Analysis and Alerting
    • Create Delivery Task
  • Operation guide
    • Baidu Intelligent Cloud Environment Preparation
    • Overview
    • Identity and access management
    • Logset Management
    • Agent
      • Install Agent on Host
      • Install Agent in K8s Environment
      • Agent Management
      • Agent Release Version
      • Set Agent Startup Parameters
    • Log Collection
      • Transmission Task Collection
        • Create Transmission Task
        • Manage Transmission Task
      • Uploading Logs Using Kafka Protocol
    • Query analysis
      • Log query
      • SQL Syntax
      • Search Syntax
    • Dashboard
      • Overview
      • Management Dashboard
      • Management Dashboard Charts
    • Alarm management
      • Alert Overview
      • Alarm strategy
        • Management alarm strategy
        • Trigger conditions
      • Alarm history
      • Alert execution statistics
      • Alarm notification
        • Alarm Notification Template
        • Alarm callback
    • Data processing
      • Log Delivery
        • Log Delivery Overview
        • Create Delivery Task
        • Manage Delivery Task
      • Scheduled SQL Analysis
        • Manage Scheduled SQL Analysis Task
        • Create Scheduled SQL Analysis Task
      • Real-Time Consumption
      • Data processing
        • Data processing
          • Overview of data processing functions
          • Process control function
          • Mapping enrichment functions
          • Event operation functions
          • Field operation functions
          • Field value extraction functions
    • Log Applications
      • Intelligent Diagnostics
  • Best Practices
    • Use Year-Over-Year and Month-Over-Month as Alert Trigger Conditions
    • BLS Integration with Kibana
    • Use BLS via Grafana
  • Development Guide
    • API Reference
      • API function release records
      • API Overview
      • Interface Overview
      • General Description
      • Service domain
      • Common error codes
      • Terminology
      • Project Related APIs
        • Create Project
        • Update Project
        • Describe Project
        • Delete Project
        • List Project
      • LogStore Related APIs
        • Create LogStore
        • Update LogStore
        • Delete LogStore
        • Describe LogStore
        • Batch Get LogStore
        • List LogStore
      • LogStream Related APIs
        • List LogStream
      • LogRecord Related APIs
        • Push log PushLogRecord
        • Obtain logrecord PullLogRecord
        • Search analysis log QueryLogRecord
        • Histogram API QueryLogHistogram
      • Fast Query FastQuery Related Interfaces
        • Create Fast Query CreateFastQuery
        • Update Fast Query UpdateFastQuery
        • Delete Fast Query DeleteFastQuery
        • Get Fast Query Details DescribeFastQuery
        • Get Fast Query List ListFastQuery
      • Index Related APIs
        • Create Index
        • Update Index
        • Delete Index
        • Describe Index
      • Log Shipper LogShipper Related Interfaces
        • Create Log Shipper
        • Update Log Shipper
        • Set Single Log Shipper Status
        • Delete Single Log Shipper
        • Bulk Delete Log Shipper
        • List Log Shipper Records
        • List Log Shipper
        • Bulk Set Log Shipper Status
        • Get Log Shipper
      • Alarm-Related Interfaces
        • CreateAlarmPolicy
        • UpdateAlarmPolicy
        • DeleteAlarmPolicy
        • ValidateAlarmCondition
        • ValidateAlarmPolicySQL
        • EnableAlarmPolicy
        • DescribeAlarmRecord
        • DisableAlarmPolicy
        • DescribeAlarmPolicy
        • ListAlarmPolicy
        • ListAlarmRecord
        • ListAlarmExecutionStats
        • ListAlarmExecutions
      • LogStore Template-Related Interfaces
        • CreateLogStoreTemplate
        • UpdateLogStoreTemplate
        • DeleteLogStoreTemplates
        • DescribeLogStoreTemplates
        • DescribeLogStoreTemplate
      • Download Log Download Related Interfaces
        • Create Download Task CreateDownloadTask
        • Get Download Task List ListDownloadTask
        • Delete Download Task DeleteDownloadTask
        • Get Download Task Address GetDownloadTaskLink
        • Get Download Task Details DescribeDownloadTask
      • LogAlarm Related Interfaces
        • SetLogAlarmStatus
        • deleteLogAlarm
        • createLogAlarm
        • listLogAlarm
        • updateLogAlarm
        • BulkDeleteLogAlarm
        • PreviewAlarmLogRecord
        • getLogAlarm
        • BulkSetLogAlarmStatus
      • Transmission Task Related Interfaces
        • Create Task CreateTask
        • UpdateTask
      • Interfaces Compatible with Elasticsearch
        • ResolveIndex
        • FieldCaps
        • TermsEnum
        • AsyncSearch
    • SDK Reference
      • Go SDK
        • Overview
        • Initialization
        • Version Release Records
        • Project Operations
        • LogStore Operations
        • Install the SDK Package
        • LogStream Operations
        • LogRecord Operations
        • FastQuery Operations
        • LogShipper Operations
        • Index Operations
        • Download Task Operations
      • Java SDK
        • Overview
        • Install the SDK Package
        • LogRecord Operations
      • iOS SDK
        • Overview
        • Quick start
        • Version Release Records
      • Android SDK
        • Overview
        • Quick start
        • Version Release Records
      • Android & iOS SDK Download
      • SDK Privacy Policy
      • SDK Developer Personal Information Protection Compliance Guide
    • Importing SLS Collection Configuration
  • FAQs
    • Common Questions Overview
    • Fault-related questions
    • Configuration-related questions
  • Log Service Level Agreement SLA
  • Document center
  • arrow
  • BLS
  • arrow
  • Development Guide
  • arrow
  • SDK Reference
  • arrow
  • Android SDK
  • arrow
  • Quick start
Table of contents on this page
  • Introduction
  • Environmental requirements
  • Install SDK package
  • Installation steps
  • Configure permissions
  • SDK directory structure
  • Quick Start

Quick start

Updated at:2025-11-03

Introduction

This document mainly introduces the installation and use of Baidu AI Cloud log service Android SDK.

This document assumes that you have enabled the Baidu AI Cloud log service.

If you haven't enabled or don't understand the log service, please log on to the Log Service Product Homepage for more help.

Environmental requirements

  • Android system version: 2.3 and above
  • It is required to register a Baidu AI Cloud user account and open the log service

Install SDK package

The Android SDK for the log service depends on OKhttp and Gson.

Installation steps

  1. Find the Baidu log service from the client SDK list of Baidu AI Cloud Developer Center and download the SDK compressed package.
  2. Extract the archive to get the jar package. The jar package should include three files: bls-android-sdk-1.X.X.jar, okhttp-3.x.x.jar, and gson-2.x.x.jar.
  3. Move the jar package to the lib (or libs) directory of your Android project.
  4. For Eclipse: Right-click on your project, go to Properties > Java Build Path > Add JARs, and import the copied jar package. For Android Studio: Right-click on your project, select Open Module Settings, navigate to Module > Dependencies > +, select File Dependency, then choose the copied jar package from the lib (or libs) directory to complete the import.

Configure permissions

Below are the Android permissions required by the log service Android SDK. Make sure these permissions are configured in your project's AndroidManifest.xml file; otherwise, the SDK will not function correctly.

XML
1<uses-permission android:name="android.permission.INTERNET"/>
2<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
3<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
4<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
5<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

SDK directory structure

Plain Text
1com.baidubce
2 ├── auth                                        //BCE signature classes
3 ├── http                                        //BCE HTTP communication classes
4 ├── internal                                    //SDK internal classes
5 ├── model                                       //BCE common model classes
6       ├── services
7       │       └── bls                                
8 │           ├── request                         //Internal BLS models, such as Request or Response
9 │           ├── BlsClient.class                 / //BLS client entry class
10 │           └── BlsClientConfiguration.class    //Configuration for BLS-specific HttpClient
11 ├── util                                        //BCE common utilities
12 ├── BceClientConfiguration.class                 // Configuration for BCE HttpClient
13 ├── BceClientException.class                    // BCE client exception class
14 ├── BceServiceException.class                   // Exception class after BCE server interaction
15 ├── ErrorCode.class                           // BCE common error codes
16 └── Region.class                              // Regions where BCE provides services

Quick Start

The basic process for uploading logs is demonstrated below.

  1. Initialize BlsClient; refer to the init () method in MainActivity for the method. (Available endpoints can be viewed in [API Reference-Service Domain Name](BLS/Development Guide/API Reference/Service domain.md).)
JAVA
1    //All APIs complete request signing through AK (Access Key ID)/SK (Secret Access Key) to pass server authentication and authorization
2    String ak = "***";
3    String sk = "***";
4 // Set authentication
5    DefaultBceCredentials stsCredentials = new DefaultBceCredentials(ak, sk);
6 // Configuration information
7    LogClientConfiguration blsConfig = new LogClientConfiguration();
8    blsConfig.setCredentials(stsCredentials);
9 // Set endpoint
10    blsConfig.setEndpoint(BLS_ENDPOINT);
11 // Set the maximum number of retries and the delay time of each retry
12    blsConfig.setRetryPolicy(new DefaultRetryPolicy(RETRY_MAX, RETRY_DELAY));
13 // Set timeout duration
14    blsConfig.withSocketTimeoutInMillis(DEFAULT_TIMEOUT_IN_MILLIS);
15 // Initialize a client
16    logClient = new BlsClient(blsConfig);
  1. Initialize the log and then upload it using the client. Log records can be in TEXT or JSON format. For TEXT log records, the logs are not processed; for JSON log records, only the first-level fields are automatically detected (nested fields are not currently supported).

    1. Upload TEXT logs
    JAVA
    1    //logstore name,set by users
    2    String logStoreName = createdLogStoreName;
    3 //logstream name,set by users
    4    String logStreamName = Settings.System.getString(MainActivity.this.getContentResolver(),Settings.System.ANDROID_ID);
    5 // Set log structure
    6    List<LogRecord> logRecordList = new ArrayList<LogRecord>();
    7    LogRecord record = new LogRecord();
    8    record.setMessage("this is log.");
    9    record.setTimestamp(System.currentTimeMillis());
    10    logRecordList.add(record);
    11 // Upload log request
    12    PushLogRequest pushLogRequest = new PushLogRequest(logStoreName, logStreamName, logRecordList);
    13    PushLogResponse response = logClient.pushLog(pushLogRequest);
    14    boolean isSuccess = response.getHttpResponse().getStatusCode() == StatusCodes.HTTP_OK;
    15    Log.e("main", "push log result: " + isSuccess);
    1. Upload JSON logs
    JAVA
    1    //logstore name,set by users
    2    String logStoreName = createdLogStoreName;
    3 //logstream name,set by users
    4    String logStreamName = Settings.System.getString(MainActivity.this.getContentResolver(),Settings.System.ANDROID_ID);
    5 // Set log structure
    6    List<LogRecord> logRecordList = new ArrayList<LogRecord>();
    7    LogRecord record = new LogRecord();
    8    record.setMessage("{\"level\":\"info\", \"status\": 200, \"cost\": 304.87}");
    9    record.setTimestamp(System.currentTimeMillis());
    10    logRecordList.add(record);
    11 // Upload log request
    12    PushLogRequest pushLogRequest = new PushLogRequest(logStoreName, logStreamName, "JSON", logRecordList);
    13    PushLogResponse response = logClient.pushLog(pushLogRequest);
    14    boolean isSuccess = response.getHttpResponse().getStatusCode() == StatusCodes.HTTP_OK;
    15    Log.e("main", "push log result: " + isSuccess);
    1. To upload specific fields processed from the log, along with the raw log text, use the JSON format. The raw log text should be included as a value for the key "@raw" in the JSON object. When processing "@raw," BLS will interpret its content as the raw log text.
    JAVA
    1    //logstore name,set by users
    2    String logStoreName = createdLogStoreName;
    3 //logstream name,set by users
    4    String logStreamName = Settings.System.getString(MainActivity.this.getContentResolver(),Settings.System.ANDROID_ID);
    5 // Set log structure
    6    List<LogRecord> logRecordList = new ArrayList<LogRecord>();
    7    LogRecord record = new LogRecord();
    8    record.setMessage("{\"@raw\":\"info 200 304.87ms this is log.\", \"level\":\"info\", \"status\": 200, \"cost\": 304.87}");
    9    record.setTimestamp(System.currentTimeMillis());
    10    logRecordList.add(record);
    11 // Upload log request
    12    PushLogRequest pushLogRequest = new PushLogRequest(logStoreName, logStreamName, "JSON", logRecordList);
    13    PushLogResponse response = logClient.pushLog(pushLogRequest);
    14    boolean isSuccess = response.getHttpResponse().getStatusCode() == StatusCodes.HTTP_OK;
    15    Log.e("main", "push log result: " + isSuccess);

For the specific usage of API used by SDK, please refer to: API Reference-Overview

Previous
Overview
Next
Version Release Records