Skip to main content
Android
iOS
Web
Windows
Unity
Flutter
React Native

Configure push notifications

You can use extension fields to implement customized push settings. This page uses force push and sending silent messages as examples to explain how to implement push extensions.

Set custom push fields

When creating a push message, you can add custom fields to the message to meet personalized business needs:


_15
// This example takes text messages as an example. The setting methods for message types such as pictures and files are the same.
_15
ChatMessage message = ChatMessage.createSendMessage(ChatMessage.Type.TXT);
_15
// Set custom push extension.
_15
JSONObject emPushExt = new JSONObject() {
_15
{
_15
put("custom", new JSONObject() {
_15
{
_15
put("key1", "value1");
_15
put("key2", "value2");
_15
}
_15
});
_15
}
_15
};
_15
// Set the push extension to the message.
_15
message.setAttribute("em_push_ext", emPushExt);

The data structure of the custom field is as follows:


_8
{
_8
"em_push_ext": {
_8
"custom": {
_8
"key1": "value1",
_8
"key2": "value2"
_8
}
_8
}
_8
}

ParametersDescription
em_push_extThe extension fixed value, cannot be modified.
customThe message extension. Use the extension method to add custom fields to the push, the value is fixed.
key1/key2Customize the specific content of the message push extension.

Force push

The user can set force push to ignore the recipient's DND setting when sending messages:


_4
// This example takes text messages as an example. The setting methods for message types such as pictures and files are the same.
_4
ChatMessage message = ChatMessage.createSendMessage(ChatMessage.Type.TXT);
_4
// Set whether to force push. This field is a built-in extension field with the following values: `true`: force push; (default) `false`: non-force push.
_4
message.setAttribute("em_force_notification", true);

Send a silent message

Sending silent messages means that the sender sets the message not to be pushed when sending it. That is, when the user is offline, Chat will not push message notifications to the user's device through the FCM push service. When the user is online again, they will receive all the messages received during the offline period.

Both silent message sending and do not disturb mode pause push messages. The difference is that silent message sending is set by the sender when sending the message, while the DND mode is set by the receiver.


_4
// This example takes text messages as an example. The setting methods for message types such as pictures and files are the same.
_4
ChatMessage message = ChatMessage.createSendMessage(ChatMessage.Type.TXT);
_4
// Set whether to send silent messages. This field is a built-in extension field with the following values: `true`: send silent messages; (default) `false`: push the message.
_4
message.setAttribute("em_ignore_notification", true);

vundefined