即使全部被覆盖,Firebase 也会显示自动通知

Firebase display automatic notification even when all overrided

我在我的应用程序中使用 Firebase 云消息传递,我能够接收远程消息、数据和我需要的一切。但即使我对远程消息不做任何操作,也会自动出现一条通知,其中包含消息的内容。

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // This line is executed, with the full message
    }
}

使用此代码,Android 通知仍会触发,我不想要它。我没有设置默认频道,即使在Android 8(我需要创建一个频道来发送通知)上,默认也有一个。

如何删除此通知?

我只想按照我自己的方式显示通知,而不是 Firebase 的方式

不要使用通知消息,而是使用数据消息。

在通知消息中,当您的应用程序处于后台且无法阻止时,firebase 将始终显示通知。

所以唯一的办法就是使用数据消息,自己处理通知。

来自:https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

Notification message: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys and an optional data payload of custom key-value pairs.

Data message: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.

在我所有的应用程序中,由于缺乏控制和自定义,我只将通知消息用于非常简单的促销活动。