Android
Application

Application

Before you start building your own chat, you should understand that your SendBird application has some restrictions on its abilities to maintain the stability of chat service and also gives you ways to work with the application users. With the following information, you can integrate the SendBird application to your app for us to work better together.


Default settings

To prevent a user's abnormal activities, a SendBird application has the following limits on the number of messages per second which a user can send and an open channel can display.

Imposed onLimitIf exceeded

User

5 messages per second

Excess messages from a user are not sent to a channel, and not saved in the database. But in the user's channel view, the messages are displayed.

Open channel

5 messages per second

Excess messages in an open channel are not displayed, but saved in the database. (This setting is not effective in a group channel.)

The limits above are basic numbers of our premium features, the spam flood protection and smart throttling, which can be adjusted only by our side. If you want assistance on the settings, contact our engineering team.


Manage connections with SendBird server

For users' seamless chat experience, our Android SDK manages connections to SendBird server at an application-wide level. The table below shows how connections between a client app's SendBird instance and our server are managed. This is according to the states of Android devices where your native app is working on.

App stateConnectionSDK behavior when going to another state

Foreground

Keep connected

Disconnects the current user from SendBird server when going to the background.
(Tries to restore the connection and keeps the current user connected to SendBird server when the connection is lost due to unexpected network issues in the foreground. In this case, the attempts of restoration process and result can be checked in the connection event handler if registered.)

Background

Disconnected

Tries to reconnect and establishes the current user's new connection with SendBird server when going to the foreground.

One user ID can make connections up to 30 devices or browsers simultaneously. All connections from one user ID are counted and reflected in the CCU (concurrently connected users) which is our service's billing standard, so be careful to use it.


Retrieve a list of users

You can retrieve a list of all or certain users in your SendBird application using an ApplicationUserListQuery instance. The next() method returns a list of User objects which contain information on users within the application.

Light Color Skin
Copy
// Retrieving all users
ApplicationUserListQuery applicationUserListQuery = SendBird.createApplicationUserListQuery();
applicationUserListQuery.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {    // Error.
            return; 
        }
    }
});

With the several different types of filters the ApplicationUserListQuery instance provides, you can retrieve a list of the specific users that match the values in the filters. Currently the ApplicationUserListQuery instance supports the following two filters:

  • UserID filter: filtering users by specifying a list of user IDs.
  • MetaDataKey filter: filtering users by specifying a metadata key and a list of its values (metadata values).
Light Color Skin
Copy
// Retrieving certain users using the UserID filter
ArrayList<String> userIds = new ArrayList<>();
userIds.add("Harry");
userIds.add("Jay");
userIds.add("Jin");

ApplicationUserListQuery applicationUserListQueryByIds = SendBird.createApplicationUserListQuery();
applicationUserListQueryByIds.setUserIdsFilter(userIds);
applicationUserListQueryByIds.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

// Retrieving certain users using the MetaDataKey filter
ArrayList<String> metaDataValues = new ArrayList<>();
metaDataValues.add("movie");
metaDataValues.add("book");
metaDataValues.add("exercise");

ApplicationUserListQuery applicationUserListQueryByMetaData = SendBird.createApplicationUserListQuery();
applicationUserListQueryByMetaData.setMetaDataFilter("hobby", metaDataValues);
applicationUserListQueryByMetaData.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {        // Error.
            return;
        }
    }
});

Block and unblock other users

A user can block other users to stop receiving any further messages from them in 1-on-1 group channels, and not to be notified of their new messages in 1-on-N group channels. You can choose whether or not a user can view which users they have blocked in the UI of the channel.

A SendBird application provides two blocking options: including or excluding blocked users in invitations and turning on/off push notifications from blocked users. The previous block modes are now deprecated and only supported for customers who have been using it from before.

  • Including or excluding blocked users in invitations: determines for a user whether or not to automatically filter out already blocked users when inviting a group of users to a new group channel. The value of this option can be manually adjusted only by our side before integrating your SendBird application to an app. If you want to change the value, contact our engineering team for further assistance. (Default: including)
  • Turning on/off push notifications from blocked users: determines for a user whether or not to receive push notifications for the messages from already blocked users within a specific 1-on-N group channel where they are members of together. The value of this option can be set individually by channel. If you want to use this option, contact our engineering team for further assistance. (Default: off)
1-on-1 group channel
Channel listPush notificationsMessages

A user's channel list will not be updated and rearranged from the blocked user's messages.

A user will not be notified that the blocked user sent a message.

New messages sent from the blocked user will not be delivered to the channel, but are saved and displayed to the blocked user's channel view. The blocked user is not aware of their blocked status.
A user can only see the messages that the blocked user has sent previously before blocking.
(If the blocked user is unblocked, a user can see all the messages except those that were sent during the blocking period.)

1-on-N group channel (group chat)
Channel listPush notificationsMessages

A user's channel list will be updated and rearranged from a blocked user's messages.

If the push notifications from blocked users is turned on, messages sent from blocked users will be notified to a user. Otherwise, they will not be notified.

All the messages from blocked users are delivered to the channel. You can choose whether or not a user can view which users they have blocked in the UI of the channel.

You can make users block and unblock other user by implementing the following code to your client app.

Light Color Skin
Copy
// Blocking a user
SendBird.blockUser(USER, new SendBird.UserBlockHandler() {
    @Override
    public void onBlocked(User user, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

// Unblocking a user
SendBird.unblockUser(USER, new SendBird.UserUnblockHandler() {
    @Override
    public void onUnblocked(SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

Note: You can also use blockUserWithUserId() and unblockUserWithUserID() methods, instead of blockUser() and unblockUser() methods, as they have the same abilities.


Retrieve a list of blocked users

By creating a BlockedUserListQuery instance and using it, you can retrieve a list of all or certain blocked users within your SendBird application. The next() method returns a list of User objects which contain information on blocked users.

Light Color Skin
Copy
// Retrieving all blocked users
BlockedUserListQuery blockedUserListQuery = SendBird.createBlockedUserListQuery();
blockedUserListQuery.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

Using the UserID filter of the BlockedUserListQuery instance, you can retrieve a list of the blocked users that match the user IDs in the filter.

Light Color Skin
Copy
// Retrieving certain blocked users using the UserID filter.
ArrayList<String> userIds = new ArrayList<>();
userIds.add("John");
userIds.add("Daniel");
userIds.add("Jeff");

BlockedUserListQuery blockedUserListQuery = SendBird.createBlockedUserListQuery();
blockedUserListQuery.setUserIdsFilter(userIds);
blockedUserListQuery.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {        // Error.
            return;
        }
    }
});

Check if a user is online

You can check if a certain user is currently connected to SendBird server.

Light Color Skin
Copy
ArrayList<String> userIds = new ArrayList<>();
userIds.add("Jeff");

ApplicationUserListQuery applicationUserListQuery = SendBird.createApplicationUserListQuery();
applicationUserListQuery.setUserIdsFilter(userIds);
applicationUserListQuery.next(new UserListQuery.UserListQueryResultHandler() {
    @Override
    public void onResult(List<User> list, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
        
        if (list.get(0).getConnectionStatus() == User.ConnectionStatus.ONLINE) {
            // User.ConnectionStatus consists of NON_AVAILABLE, ONLINE, and OFFLINE.
        }
    }
});