【问题标题】:Android Hide Notification from FirebaseAndroid 从 Firebase 隐藏通知
【发布时间】:2018-12-27 13:37:26
【问题描述】:

是否可以隐藏我通过我的 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 面板测试它
  • @OussemaAroua“删除通知块”?你到底是什么意思?
  • 如以下答案所示

标签: java android firebase firebase-cloud-messaging


【解决方案1】:

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

所以不要发送:

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

},

您可以发送:

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

},

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

【讨论】:

  • 所以我需要将对象从“通知”重命名为“数据”,好的,我需要尽快测试这个:)
  • @Jonnotdoexx 是的,如果您想自己处理显示通知,您将无法收到“通知”对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多