Firebase 消息传递 - 当应用程序在后台时创建平视显示 [英] Firebase Messaging - Create Heads-Up display when app in background

查看:32
本文介绍了Firebase 消息传递 - 当应用程序在后台时创建平视显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 FCM,当应用处于后台或未运行时,我会在系统托盘中收到推送通知.当应用程序处于前台时,我可以覆盖 onMessageReceived 并使用 NotificationCompat 创建自己的提醒通知.

With FCM I receive push notifications in the system tray when the app is in the background or not running. When the app is in the foreground I can override onMessageReceived and create my own heads-up notification with NotificationCompat.

当我的应用在后台或未运行时,有没有办法创建提醒通知?

Is there a way to create a heads-up notification when my app is in the background or not running?

谢谢

这里是我通过 curl 使用的消息负载以供参考 https://fcm.googleapis.com/fcm/send

For reference here is the message payload I am using via curl to https://fcm.googleapis.com/fcm/send

{
  "to":"push-token",
    "content_available": true,
    "priority": "high",
    "notification": {
      "title": "Test",
      "body": "Mary sent you a message!",
      "sound": "default"
    },
    "data": {
      "message": "Mary sent you a Message!",
      "notificationKey":"userID/notification_type",
      "priority": "high",
      "sound": "default"
    }
}

推荐答案

只有当您的应用程序处于后台或未运行时,您才会收到提醒通知.如果您的手机没有被使用,那么您将收到系统托盘通知或锁定屏幕通知.

You will get heads up notification only if you are using some other app while your app is in background or not running. If your phone is not being used then you will receive system tray notification or lock screen notification.

如果您使用应用服务器通过 http 协议发送推送通知,那么您甚至可以在发送到 fcm 端点的 json 数据中将优先级设置为高.

如果您使用的是 firebase 控制台,请在高级通知部分设置下确保优先级较高.

高优先级将确保您在大多数情况下都能收到提醒通知.

High priority will ensure you receive heads up notifications in most cases.

编辑:这就是您编辑后的 ​​json 应该是什么样子才能成功测试 -

EDIT: This is how your edited json should look like for successful test -

{
  "to":"push-token",
    "priority": "high",
    "notification": {
      "title": "Test",
      "body": "Mary sent you a message!",
      "sound": "default",
      "icon": "youriconname"
    }
}

youriconname 是您要设置为通知图标的可绘制资源的名称.

youriconname is the name of drawable resource that you want to set as your notification icon.

出于测试目的,我省略了数据.就这么多应该给你提醒通知.

这篇关于Firebase 消息传递 - 当应用程序在后台时创建平视显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆