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

Configure push notification preferences

Copy link

Push notification preferences allow you to control when and how users receive push notifications from Sendbird Chat. You can configure trigger options, Do Not Disturb schedules, and snooze periods to customize the notification experience.

Register or unregister the current user's registration token with the Sendbird server to turn push notifications on or off in the user's app. Call these methods after the user connects to the Sendbird server using the SendbirdChat.connect() method.

Through PushTriggerOption, the current user can choose which type of messages will trigger push notifications, or disable all push notifications. You can also enable Do Not Disturb and snooze features using the setDoNotDisturb() and setSnoozePeriod() methods.

KotlinKotlinKotlinKotlin
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.
            }

            // ...
        }
    }
}

Push trigger options

Copy link

The PushTriggerOption enum 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.

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

    // ...
}

Channel-level push trigger options

Copy link

The GroupChannel.PushTriggerOption enum 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.

KotlinKotlinKotlinKotlin
// 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 notifications on the current user's app according to a specified schedule, use the Do Not Disturb feature.

When evaluating whether to suppress a notification, the server checks in the following priority order:

  1. Snooze: If snooze is active, notifications are paused regardless of other settings.
  2. Day-of-week DND schedules: If weekly DND schedules are configured, the server checks the current time against the configured windows.
  3. Legacy DND: If no weekly DND schedules exist, the legacy setDoNotDisturb() settings are used.

Day-of-week DND schedules and legacy DND are mutually exclusive — setting weekly DND schedules automatically disables legacy DND.

Note: The setDoNotDisturb() and getDoNotDisturb() methods have been deprecated as of Chat SDK v4.35.0. Use setWeeklyDoNotDisturb() and getWeeklyDoNotDisturb() instead for more flexible scheduling options.

Note: You can also configure Do Not Disturb for a user through the Platform API. To learn more, see Update push notification preferences.

KotlinKotlinKotlinKotlin
// Deprecated as of v4.35.0. Use setWeeklyDoNotDisturb() instead.
// 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.
    }

    // ...
}

Weekly Do Not Disturb

Copy link

Weekly Do Not Disturb allows you to set different Do Not Disturb time windows for each day of the week. This replaces the single-window setDoNotDisturb() method with more flexible scheduling.

Note: When evaluating whether to suppress a notification, the server checks snooze first, then weekly DND schedules, then legacy DND. Setting weekly DND schedules automatically disables legacy DND.

Set weekly Do Not Disturb schedules

Copy link
val schedules = mapOf(
    DayOfWeek.MONDAY to listOf(
        TimeWindow(9, 0, 18, 0) // 9:00 AM to 6:00 PM
    ),
    DayOfWeek.TUESDAY to listOf(
        TimeWindow(9, 0, 12, 0), // 9:00 AM to 12:00 PM
        TimeWindow(13, 0, 18, 0)  // 1:00 PM to 6:00 PM
    ),
    DayOfWeek.WEDNESDAY to listOf(
        TimeWindow(9, 0, 18, 0)
    )
)
val timeZone = TimeZone.getDefault()

SendbirdChat.setWeeklyDoNotDisturb(schedules, timeZone) { e ->
    if (e != null) {
        // Handle error.
    }

    // Weekly DND schedule is successfully set.
}

TimeWindow

Copy link
Property nameTypeDescription

startHour

int

Specifies the start hour in 24-hour format. Range: 0-23.

startMin

int

Specifies the start minute. Range: 0-59.

endHour

int

Specifies the end hour in 24-hour format. Range: 0-23.

endMin

int

Specifies the end minute. Range: 0-59.

Cross-midnight windows

Copy link

A DndTimeWindow only accepts time ranges within a single day, where startHour:startMinute must be strictly before endHour:endMinute. To create a DND window that spans midnight, use the DndTimeWindow.overnight() factory method. This method splits the window into two separate day entries on the client side before sending them to the server.

// Create a cross-midnight DND window: Monday 22:00 to Tuesday 07:00.
// overnight() splits this into:
//   MONDAY: [22:00-23:59]
//   TUESDAY: [00:00-07:00]
val overnightSchedule = DndTimeWindow.overnight(DayOfWeek.MONDAY, 22, 0, 7, 0)

SendbirdChat.setWeeklyDoNotDisturb(overnightSchedule, TimeZone.getDefault()) { e ->
    if (e != null) {
        // Handle error.
    }

    // Cross-midnight DND schedule is successfully set.
}

Get weekly Do Not Disturb schedules

Copy link

Retrieve the current weekly Do Not Disturb configuration for the user.

SendbirdChat.getWeeklyDoNotDisturb { schedules, timeZone, e ->
    if (e != null) {
        // Handle error.
    }

    // Weekly DND schedules successfully retrieved.
    schedules?.forEach { (dayOfWeek, timeWindows) ->
        timeWindows.forEach { timeWindow ->
            val start = "${timeWindow.startHour}:${String.format("%02d", timeWindow.startMin)}"
            val end = "${timeWindow.endHour}:${String.format("%02d", timeWindow.endMin)}"
            // Process schedule for each day.
        }
    }
}

Clear weekly Do Not Disturb schedules

Copy link

Remove all weekly Do Not Disturb schedules for the user.

SendbirdChat.clearWeeklyDoNotDisturb { e ->
    if (e != null) {
        // Handle error.
    }

    // Weekly DND schedules successfully cleared.
}

Snooze

Copy link

To snooze notification messages for a specific period of time, use the snooze feature.

Note: You can also configure snooze for a user through the Platform API. To learn more, see Update push notification preferences.

KotlinKotlinKotlinKotlin
// 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.
    }

    // ...
}