android 融云发送自定义消息,融云实时音视频集成如何通过RongRTCLib发送自定义消息...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

发送端:1. 继承 MessageContent生成自定义消息类

示例代码:注意,flag必须指定为 MessageTag.STATUS

@MessageTag(value = "SealRTC:SetRTCRoom", flag = MessageTag.STATUS)public class RTCRoomMessage extends MessageContent { private String userId; public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public int getType() { return type; } public void setType(int type) { this.type = type; } private int type; public RTCRoomMessage(String userId, int type) { this.userId = userId; this.type = type; } public RTCRoomMessage(byte[] data) { try { JSONObject jsonObject = new JSONObject(new String(data)); userId = jsonObject.getString("userId"); type = jsonObject.getInt("type"); } catch (JSONException e) { e.printStackTrace(); } } @Override public byte[] encode() { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("userId", userId); jsonObject.put("type", type); return jsonObject.toString().getBytes(); } catch (JSONException e) { e.printStackTrace(); } return new byte[0]; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(userId); dest.writeInt(type); } public RTCRoomMessage(Parcel parcel) { userId = parcel.readString(); type = parcel.readInt(); } public static final Creator CREATOR = new Creator() { @Override public RTCRoomMessage createFromParcel(Parcel source) { return new RTCRoomMessage(source); } @Override public RTCRoomMessage[] newArray(int size) { return new RTCRoomMessage[size]; } };}2.在初始化的地方注册自定义消息:

RongIMClient.registerMessageType(RTCRoomMessage.class)

3. 加入房间成功后,发送自定义消息:

rtcRoom.sendMessage( roomId, messageContent, callback)

接收端:1. 实现发送端的步骤 1 和 2;2. 注册RongRTCEventsListener回调,并在onReceiveMessage(Message)方法中处理自定义消息,示例代码如下: MessageContent messageContent = message.getContent(); if (messageContent instanceof RTCRoomMessage){ RTCRoomMessage rtcRoomMessage = (RTCRoomMessage) messageContent; String userId = rtcRoomMessage.getUserId(); int type = rtcRoomMessage.getType(); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值