简体   繁体   English

Android 隐藏来自 Firebase 的通知

[英]Android Hide Notification from Firebase

Is it possible to hide a notification which I receive from firebase through my api.是否可以隐藏我通过我的 api 从 firebase 收到的通知。 Currently I am accessing the notification iny my MyFirebaseMessagingService like this:目前,我正在像这样访问 MyFirebaseMessagingService 中的通知:

@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.我不想在状态栏中向用户显示消息,我只是为了接收消息并保存它。

Yes.是的。 If you send from your API a notification object (which you probably do), the notification will be handled by the system.如果您从您的 API 发送一个通知对象(您可能会这样做),该通知将由系统处理。

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.这样,如果您想向用户显示通知,您将需要自己创建通知,但您将能够捕获数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM