Android集成融云以后,设置会话消息免打扰所需要的方法无需多说:
RongIM.getInstance().setConversationNotificationStatus(
conversationType,
targetId,
notificationStatus,
new RongIMClient.ResultCallback
<Conversation.ConversationNotificationStatus>()
{
@Override public void onSuccess(Conversation.ConversationNotificationStatus status)
{}
@Override public void onError(RongIMClient.ErrorCode errorCode) { }
});
但是设置完成后发现收到消息还是有通知及声音提醒。
经过测试以后发现退出APP后重新进入就可以了,于是猜测这个函数只是向融云服务更新了数据,本地却没有更新,所以在onSuccess里面通知会话列表更新就可以了。更新用这个函数:
ConversationListFragment.onRestoreUI();
ConversationListFragment就是你初始化会话列表的时候创建的那个
public void setupConversationFragment(Uri uri)
{
mConversationListFragment = new ConversationListFragment();
mConversationListFragment.setUri(uri);
FragmentManager manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.fl_conversation, mConversationListFragment);
transaction.commit();
manager.executePendingTransactions();
}
如果会话列表和设置消息免打扰的地方不是同一个页面,可以用广播进行通知。