繁体   English   中英

Xamarin HMS Push Kit、通知消息、参数“foreground_show”被忽略?

[英]Xamarin HMS Push Kit, notification message, parameter "foreground_show" is ignored?

根据华为官方文档,“您可以设置 message.android.notification.foreground_show 字段,使通知消息不被 NC 显示。在这种情况下,当您的应用程序在前台运行时,通知消息将透明传输到您的应用程序,并由您的应用程序处理和显示。”

示例代码:

{
"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"
    ]
}

}

我对这个参数有问题,它似乎只是被忽略了。 我创建了一个实现 HmsMessageService 类的消息服务,然后覆盖了它的 OnMessageReceived(RemoteMessage message) 方法。

我的应用程序成功从服务器获取访问令牌,在前台接收数据消息,我的设备在应用程序终止或在后台接收通知消息,然后在用户点击时启动应用程序,但当应用程序在前台时我仍然无法拦截通知消息.

有没有其他人有这个问题?

您必须为您的 Activity 实现IHmsPushEvent接口,否则您将无法监听事件。 该接口的函数提供监听 HmsPush 事件。

解决方案:

  1. 为 Activity 实现IHmsPushEvent接口。
  2. 配置OnMessageReceived方法。
  3. 发送通知后,将收到远程消息。
  4. 使用GetNotification方法获取通知数据。

示例代码:

        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.

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