是否可以隐藏我通过 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()));
}
}
我不想在状态栏中向用户显示消息,我只是为了接收消息并保存它。
是的。如果您从 API 发送通知对象(您可能会这样做),则通知将由系统处理。
因此,与其发送:
"notification":{
"title": "New Notification!",
"body": "Test"
},
您可以发送:
"data":{
"title": "New Notification!",
"body": "Test"
},
这样,如果要向用户显示通知,则需要自己创建通知,但您将能够捕获数据。