Eradash
Eradash

Reputation: 422

Firebase display automatic notification even when all overrided

I use Firebase Cloud Messaging in my app, and I'm able to receive remote messages, with the data and everything I need from it. But even when I do nothing with the remote message, a notification appears automatically, with the content of the message.

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

With this code, the Android notification is still triggered, and I don't want it. I did not setup a default channel, and even on Android 8 (where I need to create a channel to send notification), there is one by default.

How can I remove this notification?

I want to display a notification only on my own terms, not on Firebase's ones

Upvotes: 3

Views: 1057

Answers (1)

humazed
humazed

Reputation: 76922

Don't use Notification message use data message instead.

in the Notification message, firebase will always show a notification when your app is in the background and there is no way to prevent it.

so the only way is to use data message and handle the notification by yourself.

from: 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.

in all of my apps, I only use Notification message for very simple promotions because of lack of control and customization.

Upvotes: 3

Related Questions