Firebase 消息传递 - 当应用程序在后台时创建平视显示

Firebase Messaging - Create Heads-Up display when app in background(Firebase 消息传递 - 当应用程序在后台时创建平视显示)
本文介绍了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 消息传递 - 当应用程序在后台时创建平视显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)