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

Push notification content templates

Copy link

Push notification content templates are pre-formatted forms that can be customized to display your own push notification messages on a user’s device. Sendbird provides two types: default and alternative. Both templates can be customized in Settings > Chat > Push notifications > Push notification content templates on Sendbird Dashboard.

As for Android, an additional implementation is required in order to display your customized push notifications. The push notification payload sent from the Sendbird server includes the content of the template, such as the title and message, and the client app can determine how to present the notification through Android-provided code. For more information on how to create a custom notification, refer to Notifications in Android's Documentation for app developers.

Huawei Mobile Service (HMS) also requires an additional implementation for custom push notifications. To learn more, see Push Kit at Huawei's Documentation.


Content templates

Copy link

There are two types of push notification content template: default and alternative. Default template is a template that applies to users with the initial notification message setting. Alternative template is used when a user selects a different notification content template instead of the default template.

The content in the template is set at the application level while the selection of templates is determined by a user or through the Platform API.

Note: When a custom channel type has its own customized push notification content template, it takes precedence over the default or alternative template.

Both templates can be customized using the variables of sender_name, filename, message, channel_name, and file_type_friendly which are replaced with the corresponding string values. As for file_type_friendly, it indicates the type of the file sent, such as Audio, Image, and Video.

See the following table for the usage of content templates.

List of content templates

Copy link
Text messageFile message

Default template

{sender_name}: {message}
An example can be Cindy: Hi!

{filename}
An example can be hello_world.jpg

Alternative template

New message arrived

New file arrived

To apply a template to push notifications, use the setPushTemplate() method. Specify the type of the template with the name as either SendbirdChat.PUSH_TEMPLATE_DEFAULT or SendbirdChat.PUSH_TEMPLATE_ALTERNATIVE.

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

    // SendbirdChat.PUSH_TEMPLATE_ALTERNATIVE has been successfully set.
}

To check the current user's push notification template, use the getPushTemplate() method as follows:

FCMHMS
SendbirdChat.getPushTemplate { templateName, e ->
    if (e != null) {
        // Handle error.
    }

    when (templateName) {
        SendbirdChat.PUSH_TEMPLATE_DEFAULT -> {
            // This sets the default template in use.
        }

        SendbirdChat.PUSH_TEMPLATE_ALTERNATIVE -> {
            // This sets the alternative template in use.
        }
    }
}