android Notification使用fcm仅显示徽章

qoefvg9y  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(144)

在使用firebase云消息时,如何在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"
    };

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题