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

查看:129
本文介绍了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 is the name of drawable resource that you want to set as your notification icon.

出于测试目的,我省略了数据.这么多应该会通知您.

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

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