[英]Xamarin HMS Push Kit, notification message, parameter "foreground_show" is ignored?
According to official Huawei docs, "You can set the message.android.notification.foreground_show field to make notification messages not displayed by NC. In this case, when your app is running in the foreground, the notification messages are transparently transmitted to your app, and processed and displayed by your app."根据华为官方文档,“您可以设置 message.android.notification.foreground_show 字段,使通知消息不被 NC 显示。在这种情况下,当您的应用程序在前台运行时,通知消息将透明传输到您的应用程序,并由您的应用程序处理和显示。”
Sample code:示例代码:
{
"message": {
"notification": {
"title": "message title",
"body": "message body"
},
"android": {
"notification": {
"foreground_show": false,
"click_action": {
"type": 1,
"action": "com.huawei.codelabpush.intent.action.test"
}
}
},
"token": [
"pushtoken1"
]
}
} }
I have a problem with this parameter, it seems it's just ignored.我对这个参数有问题,它似乎只是被忽略了。 I've created a message service that implements HmsMessageService class, then have overridden its OnMessageReceived(RemoteMessage message) method.
我创建了一个实现 HmsMessageService 类的消息服务,然后覆盖了它的 OnMessageReceived(RemoteMessage message) 方法。
My app succesfully obtains access tokens from server, receives data messages when in foreground, my device receives notification messages when app killed or in background and then starts an app on user tap, but I still can't intercept notification messages when app is in foreground.我的应用程序成功从服务器获取访问令牌,在前台接收数据消息,我的设备在应用程序终止或在后台接收通知消息,然后在用户点击时启动应用程序,但当应用程序在前台时我仍然无法拦截通知消息.
Has anyone else had this problem?有没有其他人有这个问题?
You have to implement IHmsPushEvent interface to your Activity or you cannot listen events.您必须为您的 Activity 实现IHmsPushEvent接口,否则您将无法监听事件。 This interfaces's functions provides the listening HmsPush events.
该接口的函数提供监听 HmsPush 事件。
Solution:解决方案:
Sample Code:示例代码:
public void OnMessageReceived(RemoteMessage message)
{
string MethodName = MethodBase.GetCurrentMethod().Name;
RemoteMessage.Notification notification = message.GetNotification();
Log.Info(MethodName,$"Title: {notification.Title}\nBody:{notification.Body}");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.