The custom tagged data defined in message payload like this.
{
"message": {
"notification": {
"title": "message title",
"body": "message body"
},
"android": {
...
},
"token": [
"pushtoken1"
]
},
"custom_data": ...
}
And I want to get this custom_data from RemoteMessage object.
public class HmsService extends HmsMessageService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
// remoteMessage.getCustomData
}
}
How to code this function?
Update
Refer the document ,you can try the following sample code:
Huawei Push Kit supports two types of messages: notification messages and data messages.
According to the data you send, you are using Notification message. The customized array of Notification message cannot be directly sent to the app. Data needs to be transferred through ClickAction
method.
The user-defined data can be directly transferred to the data field in a Data Messages,and you can use onMessageReceived
method to receive it.
For more details, you can refer to the following Docs:
Try with the following code.
if (remoteMessage.getData().containsKey("custom_data")) {
remoteMessage.getData().get("custom_data");
}
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.