简体   繁体   中英

Huawei Push Kit in Android : Send notification message and data message

I am seeing how Huawei Push Kit works in Android. For this I am using postman to send the notifications, I am sending a notification message and a data message. Notification messages are seen in the notification area, but I can't get the data that I sent in the data message. I would like to know how to get them both when the app is in foreground and background.

在此处输入图像描述

  1. There's a difference between HMS Core Push Kit and FCM. Notification messages will be delivered to the system tray, and data messages will be delivered to the onMessageReceived method by default when using HMS Core Push Kit. So notification message title and body cannot be obtained.

If you want to pass data to your app when sending notification message, you can tap the notification message to trigger the corresponding action such as opening the app, a web page, or a specific page in the app. To obtain data with customized actions, see docs .

  1. For the data message parameters, see this:
{
    "validate_only": false,
    "message": {
        "data": "{'param1':'value1','param2':'value2'}",
        "token": [
            "pushtoken1",
            "pushtoken2"
        ]
    }
}

and get the data with the onMessageReceived() method.

You have to include "foreground_show": false to get the message "data" payload to get delivered to "onMessageReceived".. otherwise it will only be displayed in the notification area .. and you wont be able to read the payload..

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/android-basic-receivemsg-0000001087370610-V5

Read "Receiving a Notification Message" Title in the above doc

When you send a push notification without explicitly setting the value of the *message.android.notification.foreground_show = **false*** , the data content won't be read because the NC (Notification Center of Huawei phones) takes care of the notification (when your app run in the foreground).

The NC doesn't implement the method of reading the data content as stated here by Huawei.

Therefore, you have to instruct your app, so that is your app handling the push-notification rather than the NC. To do so you have to:

  • message.android.notification.foreground_show = false in the payload (See here )
  • You need to declare the implementation class of HmsMessageService in the AndroidManifest.xml file of the app (See here ).

Here you can find all the details about the payload of a Downlink Messages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM