【发布时间】:2021-08-07 08:54:57
【问题描述】:
我使用以下代码通知图像来自可绘制对象的位置。但是,我想使用图像 URL 来使用我的 Firebase 存储中的图像。我怎样才能做到这一点。我尝试添加 URL,但出现错误。
val bitmap = BitmapFactory.decodeResource(applicationContext.resources,R.drawable.product_image)
val bitmapLargeIcon = BitmapFactory.decodeResource(applicationContext.resources,R.drawable.comp_logo)
这是完整的代码。
private fun sendNotification(title: String, message: String) {
val intent: Intent = Intent(this, SplashActivity::class.java).apply {
flags=Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0,intent, 0)
val bitmap = BitmapFactory.decodeResource(applicationContext.resources,R.drawable.product_image)
val bitmapLargeIcon = BitmapFactory.decodeResource(applicationContext.resources,R.drawable.comp_logo)
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.product_image)
.setContentTitle(title)
.setContentText(message)
.setLargeIcon(bitmapLargeIcon)
.setStyle(NotificationCompat.BigPictureStyle().bigPicture(bitmap))
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
with(NotificationManagerCompat.from(this)) {
notify(notificationId, builder.build())
}
}
【问题讨论】:
标签: android kotlin android-notifications