问题描述
这是平台错误还是我的实现中的一些问题?它似乎与重要性级别无关。安卓版本为 8.1.0。目标 SDK 是 22(不幸的是我一直坚持)。
val defaultChannelId = AppConstants.NOTIFICATION_DEFAULT_ID
val defaultChannelName = "New Orders - high priority"
val defaultChannel = NotificationChannel(
defaultChannelId,defaultChannelName,notificationmanager.IMPORTANCE_HIGH
)
defaultChannel.setSound(defaultSound,attributes)
defaultChannel.description = "When a new order arrives"
val notificationmanager = notificationmanagerCompat.from(this)
notificationmanager.createNotificationChannel(defaultChannel)
点击按钮:
出现通知:
val builder = NotificationCompat.Builder(requireContext(),AppConstants.NOTIFICATION_DEFAULT_ID).apply {
setContentTitle("New Order Received")
setContentText("Fetching order...$payload")
setSmallIcon(R.drawable.outline_receipt_white_24)
setSound(Uri.parse("android.resource://" + activity?.packageName + "/" + R.raw.notification_decorative))
setCategory(NotificationCompat.CATEGORY_STATUS)
priority = NotificationCompat.PRIORITY_HIGH
setProgress(0,true)
}
val notificationmanager = notificationmanagerCompat.from(requireContext())
notificationmanager.notify(payload,builder.build())
通知不出现:
val builder = NotificationCompat.Builder(requireContext(),AppConstants.NOTIFICATION_DEFAULT_ID).apply {
setContentTitle("New Order Received")
setContentText("Fetching order...$payload")
setSound(Uri.parse("android.resource://" + activity?.packageName + "/" + R.raw.notification_decorative))
setCategory(NotificationCompat.CATEGORY_STATUS)
priority = NotificationCompat.PRIORITY_HIGH
setProgress(0,builder.build())
解决方法
这是平台错误还是我的实现中的一些问题?
两者都不是,假设您暗示该错误在奥利奥中。您总是应该提供一个小图标以显示在状态栏中。旧版 Android 中存在一个错误,您可以破解 Notification
使其不显示此类图标。恶意软件作者认为这很棒,Google 最终修复了它。