安卓如何从Firebase隐藏通知

3

我是否能够隐藏通过我的 API 从 Firebase 接收到的通知?当前,我通过以下方式在 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()));
    }
}

我不想在状态栏中向用户显示消息,我只是想接收消息并保存它。


请仅删除通知块,我认为您无法从Firebase面板进行测试。 - Oussema Aroua
@OussemaAroua “移除通知块”?您具体指的是什么? - Jon not doe xx
as the answer below indicate - Oussema Aroua
1个回答

2

是的。如果您从API发送通知对象(您可能会这样做),系统将处理该通知。

因此,而不是发送:

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

你可以发送:

},

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

这样一来,如果想向用户展示通知,您就需要自己创建通知,但是您将能够捕获数据。


所以我需要将对象从“notification”重命名为“data”,好的,我需要尽快测试这个 :) - Jon not doe xx
@Jonnotdoexx,如果您想自己处理通知的显示,那么您将无法接收“notification”对象。 - sale0303

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接