Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Notifications
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Configure notification preferences

By registering or unregistering the current user's registration token to the Sendbird server as below, you can turn push notifications on or off in the user's client app. The registration and unregistration methods in the code below should be called after a user has established a connection with the Sendbird server by calling the SendbirdChat.connect() method.

FCMHMS
fun setPushNotification(boolean enable) {
    if (enable) {
        SendbirdChat.registerPushToken(pushToken) { status, e ->
            if (e != null) {
                // Handle error.
            }
        }
    }
    else {
        // If you want to unregister the current device only, call this method.
        SendbirdChat.unregisterPushToken(pushToken) { e ->
            if (e != null) {
                // Handle error.
            }

            // ...
        }

        // If you want to unregister all devices of the user, call this method.
        SendbirdChat.unregisterPushTokenAll { e ->
            if (e != null) {
                // Handle error.
            }

            // ...
        }
    }
}

The SendbirdChat.PushTriggerOption method allows users to configure when to receive notification messages as well as what types of messages trigger notification messages. The following are the available options.

List of push trigger options

OptionDescription

ALL

When disconnected from the Sendbird server, the current user receives notifications for all new messages including messages the user has been mentioned in.

MENTION_ONLY

When disconnected from the Sendbird server, the current user only receives notifications for messages the user has been mentioned in.

OFF

The current user doesn't receive any notifications.

FCMHMS
// Send notifications only when the current user is mentioned in messages.
SendbirdChat.setPushTriggerOption(SendbirdChat.PushTriggerOption.MENTION_ONLY) { e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

The GroupChannel.PushTriggerOption method also allows users to configure the trigger for notification messages as well as turn notifications on or off for each channel. The following are the available options.

List of push trigger options

OptionDescription

DEFAULT

The current user’s push notification trigger settings are automatically applied to the channel. This is the default setting.

ALL

When disconnected from the Sendbird server, the current user receives notifications for all new messages in the channel including messages the user has been mentioned in.

MENTION_ONLY

When disconnected from the Sendbird server, the current user only receives notifications for messages in the channel the user has been mentioned in.

OFF

The current user doesn't receive any notifications in the channel.

FCMHMS
// Apply the user's push notification setting to the channel.
groupChannel.setMyPushTriggerOption(GroupChannel.PushTriggerOption.DEFAULT) { e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

If you want to routinely turn off push notification on the current user's client app according to a specified schedule, use our Do Not Disturb feature like the following.

Note: The Do Not Disturb feature can also be set for a user with our update push notification preferences API.

FCMHMS
// The current user won't be receiving notification messages during the specified time of the day.
SendbirdChat.setDoNotDisturb(true, START_HOUR, START_MIN, END_HOUR, END_MIN, TimeZone.getDefault().getID()) { e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

To snooze notification messages for a specific period of time, use our snooze feature as below.

Note: The snooze notifications can also be set for a user with the update push preferences API.

FCMHMS
// The current user won't be receiving notification messages during the specified period of time from START_TS to END_TS.
SendbirdChat.setSnoozePeriod(true, START_TS, END_TS) { e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}