Нет звука и нет собственного маленького значка на push-уведомлении - PullRequest
0 голосов
/ 11 ноября 2019

Я реализовал push-уведомления с помощью Firebase Cloud Messaging, и все работает отлично, кроме пары проблем с настройкой:

  1. Когда я отправляю тестовое уведомление из инструмента Notification Composer, тогдамаленькая иконка, которую я установил в манифесте, показывает отлично. Но если я получаю «органическое» уведомление, которое было сгенерировано в результате действительного действия в приложении, то маленький значок - просто серый круглый круг. Я установил значок как в наборе, так и в функции построителя уведомлений.

  2. Независимо от того, отправлено ли уведомление от композитора или органически, нет звуков и вибрациикогда он получен. Пользователь может знать об этом, только если он проверит свой лоток. Я вообще не пытался настроить его, он просто не работал с настройками по умолчанию.

Этот код я использую для создания уведомлений:

private fun sendNotification(messageBody: String) {
    val intent = Intent(this, MainActivity::class.java)
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
    val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
        PendingIntent.FLAG_ONE_SHOT)

    val channelId = getString(R.string.new_reservations_notification_channel_id)
    val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val notificationBuilder = NotificationCompat.Builder(this, channelId)
        .setSmallIcon(R.drawable.ic_logo)
        .setContentTitle(getString(R.string.new_order))
        .setContentText(messageBody)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent)

    val notificationManager = getSystemService(Application.NOTIFICATION_SERVICE) as NotificationManager ////is this a good context? "Appplication? It was "Context" before and unresolved

    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(channelId,
            "Channel human readable title",
            NotificationManager.IMPORTANCE_HIGH)

        channel.lightColor = Color.GRAY
        channel.enableLights(true)
        channel.description = "Notifications for new reservations"
        val audioAttributes = AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION)
            .build()
        channel.setSound(defaultSoundUri, audioAttributes)

        notificationManager.createNotificationChannel(channel)
    }

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
}

И у меня есть это в моем манифесте внутри тега приложения:

<meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_logo" />

1 Ответ

0 голосов
/ 11 ноября 2019

Пожалуйста, ознакомьтесь с проектом firebase-sample в GitHub. Может быть, вы что-то упускаете в androidManifest.xml

...