4

On Huawei device (Android 9) my app does not show numbers on app icon for push notification. In the settings from the device under "App icon badges" I can switch the "Badge disply mode" between "Numbers" and "Dots". If I use dots, everything works fine and a dot is shown but if I use numbers my app is not in the list and show nothing on the icon.

settings

I tested the following permissions for huawei but no success

<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/>
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS"/>

Do i have to use other permissions or implement something special to be in the list for numbers and be able to show numbers on the app icon?

nasibu
  • 83
  • 1
  • 4

2 Answers2

1

Push Kit provides an API for setting badges on the server. You can encapsulate badge parameters in messages. When sending a push request, you can set the add_num, class, and set_num parameters to set the badge.

Sample code for setting a badge on the server:

{
    "validate_only": false,
    "message": {
        "notification": {
            "title": "message title ",
            "body": "message body"
        },
        "android": {
            "notification": {
                "click_action": {
                    "type": 2,
                    "url": "https://example.com"
                },
                "badge": {
                    "add_num": 1,
                    "class": "com.huawei.codelabpush.MainActivity",
                    "set_num": 10
                }
            },
            "ttl": "1000"
        },
        "token": [
            "pushtoken1"
        ]
    }
}

For more information, see docs.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
0

Try Notification.Builder setNumber (int number).

dilip
  • 63
  • 2
  • 10