推送通知中没有声音,也没有自定义的小图标

我已经使用Firebase Cloud Messaging实现了推送通知,除了几个自定义问题之外,其他一切都正常运行

  1. 当我从Notification Composer工具发送测试通知时,我在清单中设置的小图标就很好了。但是,如果我收到一个“有机”通知,该通知是通过应用程序中的实际操作生成的,则小图标只是一个灰色的圆形圆圈。我已经在menifset和“通知”构建器功能中设置了图标。

  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" />
zhangweiw 回答:推送通知中没有声音,也没有自定义的小图标

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3125822.html

大家都在问