android 推送的小图标,android - 推送通知中没有声音并且没有自定义的小图标 - 堆栈内存溢出...

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

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

无论通知是从作曲家发送的,还是有机发送的通知,收到通知时都不会发出声音,也不会产生振动。 用户只有检查托盘才能知道。 我根本没有尝试过自定义此功能,只是默认设置不起作用。

这是我用来构建通知的代码:

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())

}

我的清单中有我的应用程序标签中的内容:

android:name="com.google.firebase.messaging.default_notification_icon"

android:resource="@drawable/ic_logo" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值