Modify a notification badge
Overview
ZPNs supports offline push notification receiver app to update the app icon badge with the number of unread messages, reminding users of the unread message count.
Prerequisites
- ZPNs SDK version 2.6.0 or above has been integrated and the function of offline push notification has been implemented. For details, please refer to this document Implement offline push notification.
- Android device or emulator with Android 9.0 or above version (real device is recommended).
Send offline push notifications with badge information
When sending messages or call invitations, the sender can modify the badge-related parameters in ZIMPushConfig to determine the changes in the badge on the receiving end.
Untitled
ZIMPushConfig pushConfig = new ZIMPushConfig();
// Whether the push notification carries badge information, default is false.
pushConfig.enableBadge = true;
// The badge increment for the target of this push notification. Set it as 1 here, which will increase the badge number of the receiving end app by 1.
pushConfig.badgeIncrement = 1;
1
Update the badge automatically
Starting from Android 8.0 (API level 26), the system will display a badge (a dot) by default after receiving a push notification from FCM.
After clearing the notification in the notification bar, the badge will also be automatically cleared.