SDKsAndroid
Add to blacklist
Add a specified user to the authenticated account blocklist using addBlacklist().
Add a specified user to the authenticated account's blocklist. Blocking is an asymmetric relationship; once blocked, the target user cannot send direct messages to the authenticated user.
Code example
OpenIMClient.getInstance().friendshipManager.addBlacklist(
new OnBase<String>() {
@Override
public void onSuccess(String data) {
// User blocked successfully
}
@Override
public void onError(int code, String error) {
// Handle error
}
},
targetUserID,
"{\"source\":\"profile-menu\"}"
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<String> | Yes | Callback delivering the asynchronous operation result. |
targetUserID | String | Yes | Target user ID to block. |
ex | String | No | Custom business extension string. Pass an empty string or omit when no extension metadata is needed. |
Return value
The successful callback indicates that the server placed the target user on the authenticated account's blocklist.
State changes after the call
Once the block takes effect, the SDK triggers the onBlacklistAdded(BlacklistInfo user) event via OnFriendshipListener. Locate and update the user entry matching user.getUserID() in your local blocklist cache:
@Override
public void onBlacklistAdded(BlacklistInfo user) {
// Received block event; update local blocklist using user.getUserID()
}For complete listener registration details, see Get the blacklist. To unblock a user, see Remove from blacklist.
Was this page helpful?