Skip to content

volcengine/ve-tls-android-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

火山引擎Android SDK for TLS

欢迎使用火山引擎SDK for Android,本文档为您介绍如何获取及调用SDK。

前置准备

服务开通

请确保您已开通了日志服务。您可前往火山引擎控制台,在左侧菜单中选择或在顶部搜索栏中搜索日志服务,进入服务控制台内完成开通流程。

获取安全凭证

Access Key(访问密钥)是访问火山引擎服务的安全凭证,包含Access Key ID(简称为AK)和Secret Access Key(简称为SK)两部分。您可登录火山引擎控制台,前往“访问控制 ”的“访问密钥”中创建及管理您的Access Key。更多信息可参考访问密钥帮助文档

获取与安装

推荐通过Gradle依赖使用火山引擎SDK for TLS

maven

相关配置

  1. 创建安卓项目。
  2. Gradle配置mavenCentral(),并引入SDK。
   implementation 'com.volcengine:volc-tls-android-sdk:1.1.5'

如果有依赖冲突,请使用指定你需要的版本(以okhttp为例子)

      implementation('com.squareup.okhttp3:okhttp') {
        version {
        strictly("you version")
        }
      }
  1. Android权限
   <uses-permission android:name="android.permission.INTERNET" />
  1. 混淆配置
   -keep class net.jpountz.** { *; }

SDK使用方法

方式一:使用client用于创建project、topic等资源,方法为同步阻塞
更多Demo参考

// 初始化client
ClientConfig clientConfig = new ClientConfig(endPoint, region, accessKey, secretKey, token);
TLSLogClient client = ClientBuilder.newClient(clientConfig);
// 创建日志项目和主题
CreateProjectRequest project = new CreateProjectRequest(projectName, region, description);
CreateProjectResponse createProjectResponse = client.createProject(project);
// 创建日志主题
CreateTopicRequest createTopicRequest = new CreateTopicRequest();
createTopicRequest.setTopicName(topicName);
createTopicRequest.setProjectId(createProjectResponse.getProjectId());
createTopicRequest.setTtl(500);
CreateTopicResponse createTopicResponse = client.createTopic(createTopicRequest);
// 写入日志
List<LogItem> logs = new ArrayList<>();
currentTimeMillis = System.currentTimeMillis();
LogItem item = new LogItem(currentTimeMillis);
item.addContent("index-", "" + 0);
item.addContent("test-key", "test-value");
logs.add(item);
PutLogsRequestV2 putLogsRequestV2 = new PutLogsRequestV2(logs, topicId, null, LZ4, "test-path", "test-file");
PutLogsResponse putLogsResponse = client.putLogsV2(putLogsRequestV2);

方式二:使用producer写入日志,支持异步非阻塞
producer更多配置参考

// 初始化producer
Producer producer = ProducerImpl.defaultProducer(
       clientConfig.getEndpoint(), clientConfig.getRegion(), clientConfig.getAccessKeyId(), clientConfig.getAccessKeySecret(),
       clientConfig.getSecurityToken());
producer.start();
// 如果不需要回调,callback参数传null即可
CallBack callBack = new CallBack() {
   @Override
   public void onComplete(Result result) {
        System.out.println("producer result:" + result);
   }
};
LogItem item = new LogItem(System.currentTimeMillis());
item.addContent("test-key", "test-value");
producer.sendLogV2("", topicId, "test-source", "test-file", item, callBack);

About

TLS android sdk repository

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages