搜索
热搜: 活动 交友 discuz
查看: 4294|回复: 0
打印 上一主题 下一主题

腾讯云IM即时通讯简单搭建

[复制链接]

160

主题

165

帖子

814

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
814
跳转到指定楼层
楼主
发表于 2020-12-17 16:32:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本人之前一直是用融云的,但是后来融云收费了,价格也太贵就一段时间停用了即时通讯,腾讯IM对于普通的APP基本是免费的。

腾讯IM免费测试版主要优点
1:不限制用户数量 对比融云只有100个用户好太多了
2:好友数量20个 这个对一般APP影响也不大
3:50个群/人


第一步:SDK接入


implementation 'com.tencent.imsdk:tuikit:xxx版本'


第二部初始化


Application里初始化


       TUIKitConfigs configs = TUIKit.getConfigs();
       configs.setSdkConfig(new V2TIMSDKConfig());
       configs.setCustomFaceConfig(new CustomFaceConfig());
       configs.setGeneralConfig(new GeneralConfig());

       TUIKit.init(this, SDKAPPID, configs);







三:模拟用户登录
  1.        String userSig = GenerateTestUserSig.genTestUserSig(uid);

  2.             V2TIMManager.getInstance().login(uid, userSig, new V2TIMCallback() {
  3.                 @Override
  4.                 public void onError(int code, String desc) {
  5.                     Toast.makeText(MainActivity.this,"注册失败",Toast.LENGTH_SHORT).show();
  6.                 }

  7.                 @Override
  8.                 public void onSuccess() {
  9.                     Log.i("TAG","注册成功");
  10.                 }
  11.             });
复制代码

其中userSig是通过工具类生成的用户秘钥 具体算法看这里,正式使用可以通过后端生成


https://cloud.tencent.com/document/product/269/32688




四:搭建消息记录界面


1:布局界面加入


  1. <com.tencent.qcloud.tim.uikit.modules.conversation.ConversationLayout
  2.         android:id="@+id/conversation_layout"
  3.         android:layout_width="match_parent"
  4.         android:layout_height="match_parent" />
复制代码



2:在acvitiy代码里

  1. // 从布局文件中获取会话列表面板
  2. ConversationLayout conversationLayout = findViewById(R.id.conversation_layout);
  3. // 初始化聊天面板
  4. conversationLayout.initDefault();
复制代码

这样就完成了简单的即时通讯项目搭建,测试可以通过后端API发送消息给安卓端



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|安卓论坛  

GMT+8, 2024-4-29 05:18 , Processed in 0.073294 second(s), 35 queries .

Powered by Discuz! X3.2

© 2001-2013 Design S!|ƽ̶

快速回复 返回顶部 返回列表