目录

Pushing a Badge Update Message

Use Cases

Badge update messages apply only to multi-device badge synchronization scenarios for instant messaging apps. This function is mainly used to set the badge number of apps. The device displays only the badge on the home screen to remind users to check for in-app message updates.

Constraints

The function of pushing badge update messages supports phones, tablets, and PCs/2-in-1 devices.

Applying for Required Permissions

To push badge update messages, your app must apply for the message self-classification permission for instant messaging notifications. For details, please refer to Message Self-Classification.

Frequency Control

During the debugging phase, the maximum number of test messages that can be pushed for each project every day is 1000. To send test messages, you need to set testMessage to true.

After formal release, the total number of messages that each app can push to a single device each day is subject to the device-based message frequency control policy. The message sending frequency is governed based on service scenarios and traffic. In cases where message sending is unnecessary or unreasonable, frequency limits will be applied.

Development Procedure

  1. Obtain a push token.

  2. Call the REST API provided by Push Kit on your app server to push a badge update message. For details, please refer to the function description for the API used to push scenario-specific messages.

    • When sending a badge update message, payload.notification cannot contain the title or body field.

    • An app can send badge update messages only after obtaining the message self-classification permission for instant messaging notifications. Such a message push request does not need to contain the category parameter.

    • Use the API request URL of the V3 version (https://push-api.cloud.huawei.com/v3/[projectId]/messages:send) to push messages.

    Example request:

    // Request URL
    POST "https://push-api.cloud.huawei.com/v3/[projectId]/messages:send"
    
    // Request header
    Content-Type: application/json
    Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
    push-type: 0
    
    // Request body
    {
      "payload": {
        "notification": {
          "badge" :
          {
            "setNum" : 99
          }
        }
      },
      "target": {
        "token": ["MAMzLg**********lPW"]
      },
      "pushOptions": {
        "testMessage": true
      }
    }
    • [projectId]: project ID. To obtain the value, sign in to AppGallery Connect, click Development and services, click the desired project, and go to Project settings.

    • Authorization: a character string in JWT format. Obtain the value by referring to Authorization.

    • push-type: The value 0 indicates the badge update message type.

    • setNum: badge number to be displayed on the app icon. The value is an integer in the range of [0, 100).

    • token: push token. Obtain the value by referring to Obtaining a Push Token.

    • testMessage (optional): indicates whether a message is a test message. The value true indicates a test message. In each project, a maximum of 1000 test messages can be sent every day. Each push can carry up to 10 tokens. For details, please refer to testMessage.

  3. Verify that the device has received the badge update message by checking whether the badge number of the app has been updated to the expected value.