Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 959
Jon not doe xx Avatar asked Sep 12 '26 11:09

Jon not doe xx


1 Answers

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.

like image 149
sale0303 Avatar answered Sep 14 '26 00:09

sale0303



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!