Browse SDKs · Android
SDKsAndroid

Send a friend request

Use addFriend() to send a friend request to a specified user.

Copy
OpenIMClient.getInstance().friendshipManager.addFriend(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            markFriendApplicationSubmitted();
        }

        @Override
        public void onError(int code, String error) {
            recordFriendApplicationFailure(code, error);
        }
    },
    "user_b",
    "Hello, I am Alex"
);

The second argument is the recipient's userID, and the third argument is the request message. A successful callback means the server received the request, not that the recipient accepted it. The target ID cannot be empty. Let a trusted application backend handle lookup by nickname, phone number, or other private fields.

Merge friend request changes through OnFriendshipListener, as documented in Get received friend requests.