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

问题:

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.


回答1:

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.

  • 发表于 2018-12-29 14:23
  • 阅读 ( 280 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除