【发布时间】:2021-04-27 16:09:45
【问题描述】:
我已经将华为推送服务集成到我的应用中,当我从华为推送服务控制台触发通知时,我可以在应用处于后台时收到通知。但是,当我们的系统后端触发华为API推送通知时,应用在后台时不会出现。
尽管应用程序处于前台或后台,但以下代码仍在执行,但标题等通知参数为空。通知对象本身不为空。
JSON 消息的内容可以作为单个字符串从 remoteMessage.getData() 接收,但值不会映射到相应的字段。
public class HuaweiNotificationHandler extends HmsMessageService{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(TAG, "getData: " + remoteMessage.getData()
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification != null) {
Log.i(TAG, "getTitle: " + notification.getTitle()
}
}
}
我们的后端执行华为提供的this API发送数据消息。
这是我们的 JSON 格式
{
"collapseKey":"dummykey",
"priority":"high",
"delayWhileIdle":false,
"dryRun":false,
"sound":"",
"contentAvailable":true,
"data":{
"data":{
"type":"A",
"id":"1111111",
"entity":"0",
"url":""
},
"restrictedPackageName":"com.aa.bb.cc" // this package name is exactly same as the huawei app package registered
},
"notification":{
"title":"Notification Title",
"icon":"ic_launcher",
"body":"Message"
}
}
【问题讨论】:
-
尝试将android对象添加到你的json
"android": { "urgency": "NORMAL", "ttl": "10000s", "notification": { "title": "test", "body": "test"}} -
@mohax 我尝试使用华为控制台中的给定示例触发数据消息,但它仍然相同。
标签: huawei-mobile-services huawei-developers huawei-push-notification