android - 在 Jetpack Compose 中设置大通知图标不起作用
问题描述
我试图在可组合通知的右侧显示一个大图标,但出现类型不匹配错误,但我使用的是.png
图像:
Type mismatch: inferred type is Int but Bitmap? was expected
我究竟做错了什么?
@Composable
fun NotificationApp() {
val context = LocalContext.current
val channelId = "MyTestChannel"
val notificationId = 0
val builder = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_edit_location)
.setContentTitle("My Test Notification")
.setContentText("This is my test notification in one line...")
.setLargeIcon(R.drawable.header) // error here
.setStyle(
NotificationCompat.BigTextStyle()
.bigText(
"This is my test notification in one line. Made it longer " +
"by setting the setStyle property. " +
"It should not fit in one line anymore, " +
"rather show as a longer notification content."
)
)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
createNotificationChannel(channelId, context)
with(NotificationManagerCompat.from(context)) {
notify(notificationId, builder.build())
}
}
谢谢你的帮助!
解决方案
该方法setLargeIcon
适用于Bitmap
.
您可以使用:
.setLargeIcon(BitmapFactory.decodeResource(context.resources,R.drawable.header))
推荐阅读
- android - 未检测到 Firebase 远程配置条件国家/地区
- ocaml - Ocalmfind 找不到 Z3 包
- apache-kafka - kafka-consumer 在赔偿期间如何工作?
- python - 反 ROC-AUC 值?
- perl - 如何在 perl 中使用对象对哈希进行排序
- libgit2 - 如何从给定文件提交?
- dialogflow-es - DialogFlow 必需参数寿命
- c# - 如何在 TabPage 标题旁边显示 ErrorProvider 错误图标?
- postgresql - ASP NET CORE 部署无法访问我在 Postgresql 上的数据库
- spring-boot - 日志不显示错误级别以下级别的文本