在使用 Firebase Cloud Messaging 时,如何使 android 通知仅在应用启动器图标上显示徽章,而不是同时显示推送通知和徽章? 假设这是我的应用程序中的通知渠道:
private fun setUpNotificationChannel() {
val id = "admin"
val name = "admin Channel"
val descriptionText = "channel description"
val importance = NotificationManager.IMPORTANCE_NONE
val mChannel = NotificationChannel(id, name, importance).apply {
description = descriptionText
setShowBadge(true)
}
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(mChannel)
}
这就是我使用 FCM 从 firebase 中的 node.js 云函数发送通知的方式:
const message = {
notification: {
title: "אבדות",
body: "מודעה חדשה ממתינה לאישור",
},
topic: "admin"
};
// Send a message to devices subscribed to the provided topic.
admin
.messaging()
.send(message)
.then((response) => {
// Response is a message ID string.
console.log("Successfully sent message:", response);
})
.catch((error) => {
console.log("Error sending message:", error);
});
我不希望推送通知出现在手机顶部,但我确实希望徽章出现在应用图标上..我该怎么做?
*我尝试从云功能中的消息中删除通知部分,但它根本没有发送通知:
const message = {
topic: "admin"
};