SDKsAndroid
Send a friend application
Initiate a friend request to a target user with an optional verification message using addFriend().
Send a friend request to a specified user along with an optional verification greeting.
Code example
OpenIMClient.getInstance().friendshipManager.addFriend(
new OnBase<String>() {
@Override
public void onSuccess(String data) {
// Friend request sent successfully
}
@Override
public void onError(int code, String error) {
// Handle error
}
},
"user_b",
"Hello, I am Alex"
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<String> | Yes | Callback delivering the asynchronous operation result. |
userID | String | Yes | Target user ID of the application recipient. |
reqMsg | String | No | Optional greeting or verification note attached to the application. |
Return value
Upon success, data in onSuccess returns a confirmation message.
State changes after the call
- Callback confirmation: The
onSuccesscallback indicates that the server recorded and dispatched the friend application; it does not indicate that the recipient has accepted it. If the recipient configured automatic approval without verification, friendship establishes immediately. - Asynchronous event delivery: The recipient receives
OnFriendshipListener.onFriendApplicationAdded, delivering the new application info to merge usinguserID. If auto-accepted, both sides receiveonFriendAdded. - Re-query calibration: The sender can inspect pending outgoing requests using Get sent friend applications. Track friend application updates across screens using
userIDas the unique identifier.
Was this page helpful?