/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Configure push notification preferences

Copy link

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.

Through PushTriggerOption, the current user can choose which type of messages will trigger push notifications, or opt to turn it off completely. Additionally, they can enable the Do Not Disturb and snooze features through setDoNotDisturb() and setSnoozePeriod() methods.

FCMHMSFCM using KTXHMS using KTX
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 on the application level. The following are the available options.

List of push trigger options

Copy link
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.

FCMHMSFCM using KTX
// 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 group channel. The following are the available 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.

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

    // ...
}

Do not disturb

Copy link

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.

FCMHMSFCM using KTXHMS using KTX
// 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.
    }

    // ...
}

Snooze

Copy link

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.

FCMHMSFCM using KTXHMS using KTX
// 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.
    }

    // ...
}