公众号
打开应用公众服务会话界面:
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
conversationType | Conversation.ConversationType | 是 | 会话类型 |
targetId | String | 是 | 目标 Id |
title | String | 是 | 聊天的标题 开发者需要在聊天界面通过 intent.getData().getQueryParameter("title"),手动设置为聊天界面的标题 |
代码示例:
RongIM.getInstance().startConversation(getActivity(), Conversation.ConversationType.APP_PUBLIC_SERVICE, "9527", "公众帐号标题");
打开公众服务号会话界面:
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
conversationType | Conversation.ConversationType | 是 | 会话类型 |
targetId | String | 是 | 目标 Id |
title | String | 是 | 聊天的标题 开发者需要在聊天界面通过 intent.getData().getQueryParameter("title"),手动设置为聊天界面的标题 |
代码示例:
RongIM.getInstance().startConversation(getActivity(), Conversation.ConversationType.PUBLIC_SERVICE, "9527", "公众帐号标题");
打开应用公众服务信息界面:
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
conversationType | Conversation.ConversationType | 是 | 会话类型 |
targetId | String | 是 | 目标 Id |
代码示例:
RongIM.getInstance().startPublicServiceProfile(getActivity(), Conversation.ConversationType.APP_PUBLIC_SERVICE, "9527");
打开公共服务号信息界面:
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
conversationType | Conversation.ConversationType | 是 | 会话类型 |
targetId | String | 是 | 目标 Id |
代码示例:
RongIM.getInstance().startPublicServiceProfile(getActivity(), Conversation.ConversationType.PUBLIC_SERVICE, "9527");
搜索公众号
通过 searchPublicService
或 searchPublicServiceByType
方法搜索已经添加的公众号列表,可以按关键字精确匹配或模糊匹配方式进行搜索。
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | Conversation.ConversationType | 是 | 会话类型 |
searchType | RongIMClient.SearchType | 是 | 搜索类型枚举 |
keywords | String | 是 | 搜索关键字 |
代码示例:
RongIM.getInstance().searchPublicService(RongIMClient.SearchType.EXACT, keywords, new RongIMClient.SearchPublicServiceCallback() {
@Override
public void onError(RongIMClient.ErrorCode e) {
}
@Override
public void onSuccess(PublicServiceProfileList publicServiceProfileList) {
}
});
RongIM.getInstance().searchPublicServicebyType(Conversation.PublicServiceType.PUBLIC_SERVICE, RongIMClient.SearchType.EXACT, keywords, new RongIMClient.SearchPublicServiceCallback() {
@Override
public void onError(RongIMClient.ErrorCode e) {
}
@Override
public void onSuccess(PublicServiceProfileList publicServiceProfileList) {
}
});
获取己关注公共账号列表:
在应用中需要展示已关注公共账号列表时,可通过 getPublicServiceList
方法获取己关注公共账号列表信息。
代码示例:
RongIM.getInstance().getPublicServiceList(new RongIMClient.SearchPublicServiceCallback() {
@Override
public void onSuccess(PublicServiceProfileList publicServiceProfileList) {
}
@Override
public void onError(RongIMClient.ErrorCode e) {
}
});
获取公众号信息
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
publicServiceType | Conversation.PublicServiceType | 是 | 公众服务类型 |
publicServiceId | String | 是 | 公众号 Id |
代码示例:
RongIM.getInstance().getPublicServiceProfile(Conversation.PublicServiceType.PUBLIC_SERVICE, publicServiceId, new RongIMClient.ResultCallback<PublicServiceProfile>() {
@Override
public void onSuccess(PublicServiceProfile profile) {
}
@Override
public void onError(RongIMClient.ErrorCode e) {
}
});
公众号操作监听:
在公众号 Activity 中调用。
回调方法说明:
参数 | 说明 |
---|---|
onFollowClick | 点击关注执行 |
onUnFollowClick | 点击取消执行 |
onEnterConversationClick | 点击进入公众号执行 |
示例代码:
/**
* 设置会话操作的监听器。
*/
RongIM.getInstance(). setPublicServiceBehaviorListener(new RongIM.PublicServiceBehaviorListener() {
@Override
public boolean onFollowClick(Context context, PublicServiceProfile info) {
return false;
}
@Override
public boolean onUnFollowClick(Context context, PublicServiceProfile info) {
return false;
}
@Override
public boolean onEnterConversationClick(Context context, PublicServiceProfile info) {
return false;
}
});
注意
如果在 Activity 里设置,需要在 Activity 销毁时,将监听设置为 null,防止内存泄露。