Jon not doe xx
Jon not doe xx

Reputation: 563

Android Hide Notification from Firebase

Is it possible to hide a notification which I receive from firebase through my api. Currently I am accessing the notification iny my MyFirebaseMessagingService like this:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Intent intent = new Intent(INTENT_FILTER);

    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    if (remoteMessage.getNotification().getBody() != null) {
        setClientId(remoteMessage);
    }
}


private void setClientId(RemoteMessage remoteMessage) {
    RemoteMessage.Notification notification = remoteMessage.getNotification();

    if (notification.getBody().equals("client_id")) {
        putClientIdToSharedPrefs((notification.getTitle()));
    }
}

I do not want to Show the message to the user in the Status bar, I just to receive the message and save it.

Upvotes: 3

Views: 2271

Answers (1)

sale0303
sale0303

Reputation: 27

Yes. If you send from your API a notification object (which you probably do), the notification will be handled by the system.

So instead of sending:

"notification":{
 "title": "New Notification!",
 "body": "Test"

},

You can send:

"data":{
 "title": "New Notification!",
 "body": "Test"

},

That way, You will need to create the notification yourself if you want to show it to the user, but you will be able to catch the data.

Upvotes: 2

Related Questions