不要在安卓工作室中显示来自Firebase的通知



以下是firebase函数中的代码:

exports.androidPushNotification = functions.database
.ref("/chat/{pushId}")
.onCreate((snapshot, context) => {
admin.messaging().sendToTopic("notification", {
data: {
senderId: snapshot.val().senderId,
},
notification: {
title: `${snapshot.val().name} has sent a message.`,
body: snapshot.val().message,
},
});
});

这是onmessagerreceived在android studio:

override fun onMessageReceived(remoteMessage: RemoteMessage) {
if(remoteMessage.notification == null){
return
}
val mAuth: FirebaseAuth = FirebaseAuth.getInstance()
if(mAuth.currentUser?.uid == null){
return
}
if(remoteMessage.data["senderId"] == mAuth.currentUser?.uid){
return
}
generateNotification(remoteMessage.notification?.title!!, remoteMessage.notification?.body!!)
}

我让每个人都订阅了一个名为"通知"的主题。

这是一个聊天应用程序,每个人都在一个大的聊天。我不想让发消息的人收到通知。

代码正在工作,如果用户发送了它,但发送方仍然收到通知,则返回。

如果要发送到某个主题,则无法排除某个订阅者接收消息。

可以做的是只发送数据消息并在代码中处理它。但是,如果您包含notification节点(正如您所做的那样),如果应用程序未被积极使用,系统将显示该通知。因此,只有在消息中只有data节点而没有notification节点时,您所做的过滤才有效。

最新更新