问题描述
使用 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 消息传递 - 当应用程序在后台时创建平视显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)