简体   繁体   English

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

[英]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:解决方案:

  1. Implement IHmsPushEvent interface to Activity.为 Activity 实现IHmsPushEvent接口。
  2. Configure OnMessageReceived method.配置OnMessageReceived方法。
  3. Remote Message will be received, after you send the notification.发送通知后,将收到远程消息。
  4. Use GetNotification method to get notification data.使用GetNotification方法获取通知数据。

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}");
        }

For more details, see docs .有关更多详细信息,请参阅文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 foreground_show 设置为 false 并且我的应用程序在后台时,如何获取推送通知以显示? - How do I get push notifications to show when foreground_show is set to false and my app is in the background? 如果在后台Android Xamarin中,获取通知消息以在前台显示我的应用程序 - Getting a notification message to show my app in foreground if in background Android Xamarin HMS 推送套件通知有时作为数据到达,有时作为同一 JSON 正文的通知到达 - HMS Push Kit Notification sometimes arrives as data and sometimes as notification for the same JSON body 如何让“onMessageReceived”触发 React Native 中的通知(HMS 推送工具包)? - How do I get 'onMessageReceived' to trigger on Notification (HMS Push Kit) in React Native? 在 HMS Push Kit 和 React Native 中收到通知时,如何获取应用自动处理的通知? - How to get a notification automatically processed by the app when received in HMS Push Kit and React Native? IBM Worklight 5.0.6-如何在应用程序处于前台时在通知区域中显示推送消息 - IBM Worklight 5.0.6 - How to show push message in notification area while app is in the foreground 华为Push Kit in Android:发送通知消息和数据消息 - Huawei Push Kit in Android : Send notification message and data message 我的手机在调用HMS Push Kit服务器API后收不到任何消息。 SDK 版本为 4.0.3.300 - My phone cannot receive any message after calling the HMS Push Kit server API. The SDK version is 4.0.3.300 华为 Push Kit 通知消息键/值是 Android 中的 null - Huawei Push Kit Notification Message key/value is null in Android 使用 HmsMessageService(HMS 推送工具包)无法在华为设备上获取通知 - Unable to get Notifications on Huawei devices with HmsMessageService (HMS push kit)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM