Уведомление переднего плана, показывающее числа вместо сообщения в android - PullRequest
0 голосов
/ 10 июля 2020

Я тестировал Pu sh Уведомление от Консоль Firebase

Я успешно получил уведомление, когда мое приложение работает Фон

enter image description here

But while in foreground whatever message I send the Notification message showing to me is like :

enter image description here

I dont know from where this Number is coming from.

Below is my code for creating notification :

     override fun onMessageReceived(p0: RemoteMessage) {
    super.onMessageReceived(p0)

    p0.notification?.let {
        val notif = NotificationCompat.Builder(this, "12345")
            .setContentTitle(p0.from)
            .setContentText(p0.to)
            .setSmallIcon(R.drawable.ic_menu_send)
            .build()
        val manager = NotificationManagerCompat.from(applicationContext)
            .notify(0, notif)
    }
}

Below is the screenshot from Firebase Console :

введите описание изображения здесь

Может ли кто-нибудь сказать мне, как я могу правильно получать свои сообщения.

ОБНОВЛЕНИЕ: Также, почему эта разница в фоновых и передних уведомлениях

Заранее спасибо.

Ответы [ 2 ]

2 голосов
/ 10 июля 2020

Вы отправляете уведомление. Вы можете получить заголовок и текст, как показано ниже

override fun onMessageReceived(p0: RemoteMessage) {
    super.onMessageReceived(p0)

    val title = message.notification.title
    val body= message.notification.body

    p0.notification?.let {
        val notif = NotificationCompat.Builder(this, "12345")
            .setContentTitle(title)
            .setContentText(body)
            .setSmallIcon(R.drawable.ic_menu_send)
            .build()
        val manager = NotificationManagerCompat.from(applicationContext)
            .notify(0, notif)
    }

Вы можете получить дополнительную информацию здесь

1 голос
/ 10 июля 2020

Данные поступают из переменной p0

Конкретно

.setContentTitle(p0.from)
.setContentText(p0.to)

Чтобы получить данные / полезную нагрузку из удаленного сообщения, вам необходимо использовать метод getData()

Итак, ваше общее создание уведомлений выглядит примерно так:

// Check if message contains a notification payload.
if (remoteMessage.getData().size() > 0) {
    Log.d("Notification", "Message Notification called ");
    if (remoteMessage.getData().get("action") != null) {
        remoteNotification(remoteMessage.getData().get("action"), remoteMessage.getData().get("arg"));
        return;
    }
...