Android融云判断是否用户已经加入黑名单和加入&移除黑名单

//先判断用户是否已经加入了黑名单
RongIM.getInstance().getBlacklistStatus(otherUserId, new RongIMClient.ResultCallback() {
@Override
public void onSuccess(RongIMClient.BlacklistStatus blacklistStatus) {
if(blacklistStatus==RongIMClient.BlacklistStatus.IN_BLACK_LIST){
Log.d(TAG,"状态为黑名单");
disturb_switch.setChecked(true);
}else{
Log.d(TAG,"状态为白名单");
disturb_switch.setChecked(false);
}
}


@Override
public void onError(RongIMClient.ErrorCode e) {


}

});




disturb_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {


if(isChecked){//加入黑名单
RongIM.getInstance().addToBlacklist(otherUserId, new RongIMClient.OperationCallback() {
@Override
public void onSuccess() {
disturb_switch.setChecked(true);
Log.d(TAG,"加入黑名单成功");
}


@Override
public void onError(RongIMClient.ErrorCode errorCode) {
disturb_switch.setChecked(false);
Log.d(TAG,"加入黑名单失败");
}
});
}else{//移除黑名单
RongIM.getInstance().removeFromBlacklist(otherUserId, new RongIMClient.OperationCallback() {
@Override
public void onSuccess() {
disturb_switch.setChecked(false);
Log.d(TAG,"移除黑名单成功");
}


@Override
public void onError(RongIMClient.ErrorCode errorCode) {
disturb_switch.setChecked(true);
Log.d(TAG,"移除黑名单失败");
}
});
}


}
});

你可能感兴趣的:(第三方)