简体   繁体   English

如何禁用或关闭来自系统托盘的通知?

[英]How to disable or turn off notification come from system tray?

Hy everyone, I am developing an app that use firebase cloud messaging.大家好,我正在开发一个使用 firebase 云消息传递的应用程序。 In this app, I am using BroadcastReceiver instead of FirebaseMessagingService.在这个应用程序中,我使用的是 BroadcastReceiver 而不是 FirebaseMessagingService。

Here, BroadcastReceiver is used to save/store notification data in SQLite either in foreground/background or app is been killed.在这里,BroadcastReceiver 用于在 SQLite 中在前台/后台或应用程序被终止时保存/存储通知数据。

The problem I am facing is, app is showing two notifications(ie one from system tray and another from app).我面临的问题是,应用程序显示两个通知(即一个来自系统托盘,另一个来自应用程序)。 I don't want notification coming from system tray.我不希望来自系统托盘的通知。

So, Is there any possible way to stop notification coming from system tray.那么,是否有任何可能的方法来阻止来自系统托盘的通知。

How are you sending the messages?你是如何发送消息的? The notification will only appear in the system tray if you are creating a Notification message (or mixed Notification and Data message) before sending.如果您在发送之前创建Notification消息(或混合NotificationData消息),则通知只会出现在系统托盘中。

The docs tell you which types of message goes to the tray and which are caught by the app's receiver, and some examples of Notification vs Data messages. 文档会告诉您哪些类型的消息会进入托盘,哪些类型的消息会被应用程序的接收器捕获,以及一些NotificationData消息的示例。

Example of Notification message Notification消息示例

var message = {
  notification: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  }
}

Example of Data message Data信息示例

var message = {
  data: {
    title: '$GOOG up 1.43% on the day',
    body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
  },
  android: {
    ttl: 3600 * 1000,
    notification: {
      icon: 'stock_ticker_update',
      color: '#f45342',
    },
  }
}

If you're using cloud functions to send messages, take a look at this reference document that outlines all parameters you can use to build messages.如果您使用云函数发送消息,请查看参考文档,其中概述了可用于构建消息的所有参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM