Have you noticed that after we unlock the phone, we always see a small red dot in the upper right corner of the App on the desktop, which is the push icon. The push icon refers to the red circle in the upper right corner of the App icon on the mobile device, and the white number in the circle represents the number of unread messages. The corner mark is a relatively light reminder. By intuitively showing the amount of information that the user has not read, it can create a sense of tension for the user, arouse the user's curiosity to read, so that the user can't help but click. Therefore, when used properly, the push corner logo helps to improve the app push open rate and maintain user stickiness.

The HMS Core push service provides an API interface for setting desktop banners, and developers can encapsulate banner parameters in messages. How does this "little red dot" function work? Below are the detailed integration steps.

one. Client API Setting Huawei Push Icon

Supported platforms:

1. System version: EMUI4.1 and above

2. Desktop version: 6.3.29

3. Supported devices: Huawei devices

Corner mark function development:

  1. Claim permissions
 < uses - permission android: name = "android.permission.INTERNET" / >
        <
        uses - permission android: name =
"com.huawei.android.launcher.permission.CHANGE_BADGE " / >
  1. Use the following method to transfer data to the Huawei desktop application where the corner label needs to be displayed.
 Bundle extra = new Bundle();
    extra.putString("package", "xxxxxx");
    extra.putString("class", "yyyyyyy");
    extra.putInt("badgenumber", i);
    context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher
    .settings/badge/"), "change_badge", null, extra);

Description of key parameters:

package: application package name

class: The application entry Activity class corresponding to the desktop icon

badgenumber: badge number

 boolean mIsSupportedBade = true;
    if (mIsSupportedBade) {
        setBadgeNum(num);
    }
    /** set badge number*/
    public void setBadgeNum(int num) {
        try {
            Bundle bunlde = new Bundle();
            // com.test.badge is your package name
            bunlde.putString("package", "com.test.badge"); 
        // com.test. badge.MainActivity is your apk main activity
        bunlde.putString("class", "com.test. badge.MainActivity");
        bunlde.putInt("badgenumber", num);                
        this.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bunlde);
    } catch (Exception e) {
        mIsSupportedBade = false;
    }
}

Special circumstances to consider:

(1) When the third application opens and exits, whether to continue to display the badge depends on the value passed by the application (when the badgenumber is 0, the badge is not displayed; when the badgenumber is greater than 0, the badge is displayed).

(2) When the third-party application package and class change, the changed information needs to be transmitted.

(3) Before calling the corner label interface, it is not necessary to obtain in advance whether the desktop supports the corner label function. When the desktop does not support the corner mark function, the interface will throw an exception, and the application can add a try ... catch(Exception e) statement to the place where the interface is called to prevent the program from crashing.

two. HMS Core push service sdk desktop corner icon settings

In the interface for sending downlink messages of Push Kit, the three parameters of BadgeNotification determine whether the badge is displayed and the quantity displayed:

The following 5 points need to be paid attention to when setting up:

1. The class field application package name + application entry Activity class name, if the wrong angle is passed, it cannot be displayed

2. The add_num field requires emui version 8.0.0 or later, and push service version 8.0.0

3. The set_num field requires emui version 10.0.0 or later, and push service version 10.1.0

4. Opening the app or clicking and clearing the notification bar message will not clear the number of corner markers. The application needs to refer to the corner marker development guide on the terminal side to clear the corner markers.

  1. "class" is required, "add_num" and "set_num" parameters are optional.

If both "add_num" and "set_num" are set to be empty, the application index number will be incremented by 1 by default.

Learn more details>>

Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee

Follow us to know the latest technical information of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙原生应用,和开发者共同成长。