android整合好视通sdk经验总结(二)

2023-05-16

一、无法正常访问好视通服务接口

当按照android整合好视通sdk经验总结(一)步骤整合完毕后,在这里修改申请的应用id和服务地址在这里插入图片描述
修改完毕后运行发现无法正常初始化sdk,错误码30,对应错误信息为无法连接到网络,经过检查后发现,我这里是用的私有的https请求,被安全拦截,因此无法连接到好视通服务。
解决办法:
在主module的application里作如下改动:
实现 X509TrustManager接口,并在oncreate()方法中加入

public class AppApplication implements X509TrustManager {

    private static TrustManager[] trustManagers;
    private static final X509Certificate[] _AcceptedIssuers = new
            X509Certificate[] {};
    @Override
    public void onCreate() {
        super.onCreate();
        //设置私有https证书信任
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                // TODO Auto-generated method stub
                return true;
            }

        });

        SSLContext context = null;
        if (trustManagers == null) {
            trustManagers = new TrustManager[] { this };
        }

        try {
            context = SSLContext.getInstance("SSL");
            context.init(null, trustManagers, new SecureRandom());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }

        HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
        }
        
    @Override
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

    }

    @Override
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        return _AcceptedIssuers;
    }
        }

即可正常访问好视通服务,app也可以正常运行。

二、对界面分屏数量进行修改

原有demo对视频人数画面做了限制,最多只能给6个人分配视频画面,超出6人不再分配视频画面,查看相关view的代码发现只对6个人的数据做了处理,因此只能分配6个画面,这里根据人数对画面做分割处理,堆叠最大人数10人
在FspUserViewGroup中对onMeasure()和onLayout()

 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int w = MeasureSpec.getSize(widthMeasureSpec);
        int h = MeasureSpec.getSize(heightMeasureSpec);

        int childrenCount = getChildCount();
        if (childrenCount <= 0) {
            return;
        }
        if (childrenCount <= 2) { // <=2
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    if (i == 0) {
                        child.measure(widthMeasureSpec, heightMeasureSpec);
                    } else {
                        child.measure(MeasureSpec.makeMeasureSpec(w / 3, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(h / 3, MeasureSpec.EXACTLY));
                    }
                }
            }
        } else if (childrenCount <= 4) { // <=4
            int cw = (w - m_margin) / 2;
            int ch = (h - m_margin - m_marginBottom) / 2;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else if (childrenCount <= 6) { // <=6
            int cw = (w - m_margin) / 2;
            int ch = (h - 2 * m_margin - m_marginBottom) / 3;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else if (childrenCount <= 8) { // <=8
            int cw = (w - m_margin) / 2;
            int ch = (h - 3 * m_margin - m_marginBottom) / 4;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else { // <=10
            int cw = (w - m_margin) / 2;
            int ch = (h - 4 * m_margin - m_marginBottom) / 5;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        }

        setMeasuredDimension(w, h);
    }


    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int childrenCount = getChildCount();
        if (childrenCount <= 0) {
            return;
        }
        if (childrenCount <= 2) { // <=2
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, r, b);
                    } else {
                        child.layout(r * 2 / 3, t, r, b / 3);
                    }
                }
            }
        } else if (childrenCount <= 4) { // <=4
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin - m_marginBottom) / 2;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, b);
                    } else {
                        child.layout(cw + m_margin, ch + m_margin, r, b);
                    }
                }
            }
        } else if (childrenCount <= 6) { // <=6
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 2 - m_marginBottom) / 3;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, b);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, b);
                    } else {
                        break;
                    }
                }
            }
        } else if (childrenCount <= 8) { // <=8
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 3 - m_marginBottom) / 4;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, 3 * ch + 2 * m_margin);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, 3 * ch + 2 * m_margin);
                    } else if (i == 6) {
                        child.layout(l, ch * 3 + m_margin * 3, cw, b);
                    } else if (i == 7) {
                        child.layout(cw + m_margin, ch * 3 + m_margin * 3, r, b);
                    } else {
                        break;
                    }
                }
            }
        } else { // <=10
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 4 - m_marginBottom) / 5;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, 3 * ch + m_margin * 2);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, 3 * ch + m_margin * 2);
                    } else if (i == 6) {
                        child.layout(l, ch * 3 + m_margin * 3, cw, 4 * ch + m_margin * 3);
                    } else if (i == 7) {
                        child.layout(cw + m_margin, ch * 3 + m_margin * 3, r, 4 * ch + m_margin * 3);
                    } else if (i == 8) {
                        child.layout(l, ch * 4 + m_margin * 4, cw, b);
                    } else if (i == 9) {
                        child.layout(cw + m_margin, ch * 4 + m_margin * 4, r, b);
                    } else {
                        break;
                    }
                }
            }
        }
    }

三、界面显示信息由userid改为username
原代码 登录好视通服务时,传入了userid和username,这里ios传入好视通sdk后的人员信息如果是中文,拿出来后是乱码,怀疑是sdk编码问题,因此为了配合ios这里也做相同的处理:先对人员信息进行URL编码处理,拿出来使用时再进行解码。

boolean result = FspManager.getInstance().login(TextUtils.equals(userid, "") ? "userid" : userid, TextUtils.equals(username, "") ? URLEncoder.encode("username") : URLEncoder.encode(username));

新建一个参会人员信息管理类FspUserInfoManager

public class FspUserInfoManager {
    /**
     * 拍照上传 项目标识id
     */
    private String rowguid = "";
    /**
     * 好视通会议室 人员数据
     */
    private static List<FspUserInfo> my_data = new ArrayList<>();
    private static FspUserInfoManager instance;

    public static synchronized FspUserInfoManager getInstance() {
        if (instance == null) {
            Class var0 = FspUserInfoManager.class;
            synchronized (FspUserInfoManager.class) {
                if (instance == null) {
                    instance = new FspUserInfoManager();
                }
            }
        }

        return instance;
    }

    /**
     * 刷新用户信息数据
     *
     * @param list 用户数据
     */
    public void refreshUserInfo(List<FspUserInfo> list) {
        if (my_data.size() > 0) {
            my_data.clear();
        }
        List<FspUserInfo> newInfoList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            FspUserInfo oldUserInfo = list.get(i);
            FspUserInfo userInfo = new FspUserInfo(oldUserInfo.getUserId(), oldUserInfo.getStatus(), URLDecoder.decode(oldUserInfo.getCustomInfo()));
            newInfoList.add(userInfo);
        }
        my_data.addAll(newInfoList);
    }

    /**
     * 根据用户id获取 用户名
     *
     * @param userId 用户 id
     * @return 用户名
     */
    public String getCustomInfo(String userId) {
        String name = "";
        if (my_data != null && !my_data.isEmpty()) {
            for (int i = 0; i < my_data.size(); i++) {
                if (TextUtils.equals(userId, my_data.get(i).getUserId())) {
                    name = my_data.get(i).getCustomInfo();
                    return name;
                }
            }
        }
        return "";
    }

    public List<FspUserInfo> getMyData() {
        return my_data;
    }

    public String getRowguid() {
        return rowguid;
    }

    public void setRowguid(String rowguid) {
        this.rowguid = rowguid;
    }
}

因为参会期间会有人员中途加入或者退出会议的情况,因此需要及时刷新用户信息,此处在MainActivity中的刷新用户状态的事件中加入refreshUserInfo

@Override
public void onEventRefreshUserStatusFinished(FspEvents.RefreshUserStatusFinished status) {
    if (m_curOperateDialog != null && m_curOperateDialog.isShowing()) {
        m_curOperateDialog.notifyDataSetChanged(status);
    }
    //个性化 更新用户信息
    if (status.isSuccess) {
        FspUserInfoManager.getInstance().refreshUserInfo((Arrays.asList(status.infos)));
    }
}

将界面上相关的需要展示人员信息的数据 从userid换成与userid对应的username即可例如:
发送消息界面userid改成username:

   @OnClick(R2.id.dialog_tv_send_select)
    public void onClickSelectReceivers(View view) {
        SenderSelectDialog senderSelectDialog = new SenderSelectDialog(getContext(), m_remoteUserId);
        senderSelectDialog.setListener(new SenderSelectDialog.onDialogItemSelectedListener() {
            @Override
            public void onItemSelected(String uidSel) {
                m_remoteUserId = uidSel;
//                dialogTvSendSelect.setText(m_remoteUserId == null ? "发送给:所有人" : "发送给:" + m_remoteUserId);
                String name = FspUserInfoManager.getInstance().getCustomInfo(m_remoteUserId);
                dialogTvSendSelect.setText(name == null ? "发送给:所有人" : "发送给:" + name);

                if (m_onDialogItemSenderSelectListener != null) {
                    m_onDialogItemSenderSelectListener.onItemSelected(uidSel);
                }
            }
        });
        senderSelectDialog.show();
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android整合好视通sdk经验总结(二) 的相关文章

  • SPI通信方式总结

    SPI xff08 Serial Peripheral interface xff09 是一种同步串行传输规范 xff0c 也是单片机外设芯片串行外设扩展接口 xff0c 该接口是一种高速 xff0c 全双工 xff0c 同步的通信总线 x
  • 轮询机制的介绍

    轮询是一种CPU决策如何提供周边设备服务的方式 xff0c 又称 程控输入输出 xff08 Programmed I O xff09 是由CPU定时发出询问 xff0c 依序询问每一个周边设备是否需要其服务 xff0c 有即给予服务 xff
  • stm32面试题总结

    1 嵌入式系统中ROM RAM Register的概念和作用是什么 xff1f ROM是只读存储器 断电后能保证数据不会丢失 xff08 硬盘 xff09 RAM是随机存储器 断电后数据会丢失 xff08 内存 xff09 Register
  • 有刷电机,无刷电机和电调的总结

    有刷直流电机工作原理 xff1a 有刷直流电机的主要结构就是定子 43 转子 43 电刷 xff0c 通过旋转磁场获得转动力矩 xff0c 从而输出动能 电刷与换向器不断接触摩擦 xff0c 在转动中起到导电和换相作用 有刷直流电机采用机械
  • leetcode刷题(五)——找出数组中唯一出现的数

    给定一个只包含整数的有序数组 nums xff0c 每个元素都会出现两次 xff0c 唯有一个数只会出现一次 xff0c 请找出这个唯一的数字 你设计的解决方案必须满足 O log n 时间复杂度和 O 1 空间复杂度 示例 1 输入 nu
  • leetcode刷题(六)——快乐数

    编写一个算法来判断一个数 n 是不是快乐数 快乐数 定义为 xff1a 对于一个正整数 xff0c 每一次将该数替换为它每个位置上的数字的平方和 然后重复这个过程直到这个数变为 1 xff0c 也可能是 无限循环 但始终变不到 1 如果这个
  • leetcode刷题(七)——移动零

    给定一个数组 nums xff0c 编写一个函数将所有 0 移动到数组的末尾 xff0c 同时保持非零元素的相对顺序 请注意 xff0c 必须在不复制数组的情况下原地对数组进行操作 示例 1 输入 nums 61 0 1 0 3 12 输出
  • STM32 HAL库 串口接收不定长数据(帧头)

    写的比较垃圾 xff0c 将就着用 欢迎各位大佬指导 xff0c 我这里要用串口中断接收两种帧头的数据 xff0c 1 以0x0D 0x0A为帧头的数据 2 xff0c 以0x55 0xA5为帧头的数据 两数据包帧头不同 大小不同 其中定义
  • freeRTOS系列教程之【第一章】FreeRTOS概述与体验

    文章目录 教程目录1 1 FreeRTOS目录结构1 1 FreeRTOS目录结构1 2 核心文件1 3 移植时涉及的文件1 4 头文件相关 1 4 1 头文件目录1 4 2 头文件 1 5 内存管理1 6 Demo1 7 数据类型和编程规
  • 【RTOS的最通俗理解】行业大佬用一篇文章带你快速理解RTOS

    文章目录 单片机 RTOS 架构 1 RTOS的概念 1 1 用人来类比单片机程序和RTOS 1 1 1 我无法一心多用1 2 2 我可以一心多用 1 2 程序简单示例 2 架构的概念 2 1 用人来类比电子产品2 2 要深入理解RTOS就
  • 开源网络模拟器ns-3 架构与实践

  • 四、freeRTOS_同步互斥与通信概述

    目录 1 同步与互斥的概念 2 同步的例子 xff1a 有缺陷 3 互斥的例子 xff1a 有缺陷 4 通信的例子 xff1a 有缺陷 5 FreeRTOS的解决方案 对应程序 xff1a 12 freertos example sync
  • 五、freeRTOS_队列的使用

    目录 1 队列的理论讲解 1 1 常规操作 2 队列的常规使用 3 队列集 1 队列的理论讲解 1 1 常规操作 队列的简化操如入下图所示 xff0c 从此图可知 xff1a 队列可以包含若干个数据 xff1a 队列中有若干项 xff0c
  • 从零开始的leetcode刷题(使用python)Day1

    从零开始用python刷leetcode xff0c 随手记录一些tips 1 哈希表 xff08 leetcode第一题两数之和 xff09 哈希表也叫作散列表 xff0c 数据结构提供了键 xff08 key xff09 和值 xff0
  • [深度学习] 神经网络中的 batch 和 epoch

    参考文章为 神经网络中Batch和Epoch之间的区别是什么 xff1f Sample Sample是单个数据 即有意义的数据的最小单位 训练数据集由许多Sample组成 batch batch是一个人为设定的超参数 batch的意思是 批
  • Windows开启ftp服务-使用Xlight FTP Server

    适用于windows系统 xff0c 使用Xlight FTP Server软件 下载地址 xff1a 点击此处下载 1 将下面的软件 xff0c 安装在电脑上 2 开启ftp服务 点击程序主界面左上角 xff0c 默认端口号为21 xff
  • 控制理论中的常用定义与定理

    以下内容摘自 应用非线性控制 对于自治系统 xff08 在本书中与定常系统等价 xff09 一句话总结 xff1a 初始状态的足够小能够保证系统状态范数的任意小 不变集理论可以在V导为半负定时推导出渐进稳定的结论 xff0c 但只适用于自治
  • centos8服务器安装nginx

    安装nginx 安装依赖包 yum span class token parameter variable y span span class token function install span gcc zlib zlib devel
  • 部署hexo遇到报错ERROR Deployer not found: git的解决办法

    部署hexo遇到报错ERROR Deployer not found git的解决办法 今天部署hexo的时候遇到一个报错 hexo c span class token operator amp amp span hexo g span
  • npm install hexo-renderer-sass时报错解决办法

    npm install hexo renderer sass时报错 在安装配置hexo博客的时候 xff0c 有的主题需要安装 span class token function npm span span class token func

随机推荐