c# - 华为。使用 Push Kit 从通知中获取数据(标题、正文、发送时间)。 Xamarin 表格

标签 c# xamarin.forms huawei-mobile-services huawei-developers huawei-push-notification

我正在尝试从通知中获取数据,当我的应用程序关闭时以及当应用程序处于后台时。我收到通知,点击它,然后在 MainActivity(来自 android 项目)中我想获取数据。 我可以在我的应用程序打开时通过 HmsMessageService 和 OnMessageReceived 来完成,没有问题。但我找不到示例,如何在应用程序关闭时执行此操作。任何帮助,请。 在 Json 中有我的通知:

        var jObject = new
        {
            message = new
            {
                notification = new
                {
                    title = titleNot,
                    body = bodyNot
                },
                android = new
                {
                    notification = new
                    {
                        foreground_show = false,
                        click_action = new
                        {
                            type = 3
                        }
                    }
                },
                token = new[] { token }
            }
        };

最佳答案

应用关闭时,可以通过自定义click_action获取参数。

在您的应用服务器上的消息正文中设置意图

{
    "message": {
        "notification": {
            "title": "message title",
            "body": "message body"
        },
        "android": {
            "notification": {
                "click_action": {
                    "type": 1,
                    "intent": "intent://com.huawei.xahmspushdemo/deeplink?#Intent;scheme=pushscheme;launchFlags=0x4000000;i.age=180;S.name=abc;end"
                }
            }
        },
        "token": [
            "pushtoken1"
        ]
    }
}

这是 document .

关于c# - 华为。使用 Push Kit 从通知中获取数据(标题、正文、发送时间)。 Xamarin 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70365046/

相关文章:

华为设备上的 Firebase 远程配置/实时数据库

android-studio - 如何在 androidOs 中找到 HarmonyOS 的替代类/方法?

c# - 从 xml 中读取属性

c# - 从 Azure 事件中心获取事件后,我是否应该将其放入队列中?

c# - INavigation 无法在 Xamarin.Forms 中使用 Prism

c# - Xamarin.Forms:导航到页面失败

android - 华为,logcat 没有显示我的应用程序的日志?

c# - IEnumerable<type> 不包含 'Contains' 的定义

c# - 需要在.NET应用程序中播放mp3文件的帮助?

android - Xamarin 在Webview中用相机上传图片