Browse SDKs · Android
Platform
SDKsAndroid

Send a friend application

Initiate a friend request to a target user with an optional verification message using addFriend().

Copy

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

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback delivering the asynchronous operation result.
userIDStringYesTarget user ID of the application recipient.
reqMsgStringNoOptional greeting or verification note attached to the application.

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback 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.
  2. Asynchronous event delivery: The recipient receives OnFriendshipListener.onFriendApplicationAdded, delivering the new application info to merge using userID. If auto-accepted, both sides receive onFriendAdded.
  3. Re-query calibration: The sender can inspect pending outgoing requests using Get sent friend applications. Track friend application updates across screens using userID as the unique identifier.