Use numeric badges on Android

更新时间:
复制 MD 格式

This topic describes how to configure numeric badges for different phone models.

Introduction

Vendor support

Configuring numeric badges involves two steps:

Step 1. Configure the client

Step 2. Configure the server

Important

The numeric badge feature is supported in Mobile Push SDK V3.9.1 and later.

Vendor support

Phone type

Bring Your Own Channel

Vendor channel

Configuration required

Huawei

Supported

Supported

Yes

Honor

Supported

Supported

Yes

Xiaomi

Supported

Supported

No

vivo

Supported

Not supported

Yes

OPPO

Not supported

Not supported

Meizu

Not supported

Not supported

Note

For Xiaomi models, the badge number represents the number of notifications for the application in the notification bar. You cannot set this number using an API.

Step 1. Configure the client

<!--Permissions required for Huawei/Honor badges-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.hihonor.android.launcher.permission.CHANGE_BADGE " />
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<!--Permissions required for vivo badges-->
<uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" />
Note
  • For Huawei and Honor models, the Mobile Push SDK only displays the badge. To clear the badge, you must manually call the API. For more information, see Numeric badge APIs.

  • To display numeric badges on Xiaomi models, enable the badge permission in the settings.

Step 2. Configure the server

Add fields when sending notifications from the server

Keyword

Type

Options

Description

Notes

AndroidBadgeAddNum

int

Optional

Sets the value to add to the badge number. The value is added to the current badge number.

This field is valid only when you send pushes through Huawei/Honor vendor channels.

If both AndroidBadgeAddNum and AndroidBadgeSetNum are specified, AndroidBadgeSetNum takes precedence.

AndroidBadgeSetNum

int

Optional

Sets a static value for the badge number.

When you send pushes through vendor channels, this field is valid only for Huawei and Honor channels. When you send pushes through the Alibaba Cloud channel, this field is valid only for Huawei, Honor, and vivo models.

AndroidBadgeClass

String

Optional

The full class name of the application's entry Activity.

This field is valid only when you send pushes through Huawei/Honor vendor channels.

Note
  • The default full class name for the entry Activity of a uniapp application is io.dcloud.PandoraEntry. Use this name if you have not modified it.

  • For more information, see Request parameters.

Data structure for sending badge information

{
  "AppKey": "******",
  "PushType": "NOTICE",
  "DeviceType": "ANDROID",
  "Target": "ACCOUNT",
  "TargetValue": "86",
  "StoreOffline": true,
  "Title": "Notification Title",
  "Body": "Notification Body",
  "AndroidOpenType": "APPLICATION",
  "AndroidPopupActivity": "******",
  "AndroidPopupTitle": "******",
  "AndroidPopupBody": "******",
  "AndroidNotificationChannel": "******",
  "AndroidTargetUserType": 1,
  "AndroidBadgeAddNum": 7,
  "AndroidBadgeClass": "******",
  "AndroidBadgeSetNum": 11
}