Anonymous
Android: большой значок в конструкторе уведомлений становится пиксельным
Сообщение
Anonymous » 29 ноя 2024, 08:11
Я создаю уведомление и устанавливаю большой значок в конструкторе, используя растровое изображение.
Я отлаживаю это растровое изображение, оно становится правильным с размером 1024*1024, но все равно после добавления в уведомление оно показывает мне пиксельное (размытое)
Код: Выделить всё
notificationBuilder?.setLargeIcon(bitmap) // using this we load bitmap you can check in below code
Вот код для создания уведомления
Код: Выделить всё
fun generateNotification(isPlaying: Boolean? = null): Notification {
val notificationBuilder = NotificationCompat.Builder(mService, CHANNEL_ID)
createNotificationChannel()
notificationBuilder.setStyle(style)
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH)
mediaSession.isActive = true
val state = if (isPlaying == true) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED
playbackStateBuilder.setState(state, mService.getCurrentPosition(), mService.getPlaybackSpeed())
val playBackState = playbackStateBuilder.build()
mediaSession.setPlaybackState(playBackState)
mediaSession.setCallback(callback)
val mediaMetadataBuilder = MediaMetadataCompat.Builder()
mediaMetadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mService.getDuration())
mediaSession.setMetadata(mediaMetadataBuilder.build())
notificationBuilder.setContentIntent(mContentIntent)
notificationBuilder.setSmallIcon(R.drawable.itunes)
.setContentTitle(mService.getCurrentMediaItem()?.mediaMetadata?.albumTitle ?: "")
.setContentText("${mService.getCurrentMediaItem()?.mediaMetadata?.subtitle} Episodes")
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCategory(NotificationCompat.CATEGORY_TRANSPORT)
val artworkUri = mService.getCurrentMediaItem()?.mediaMetadata?.artworkUri
if (artworkUri != null) {
artworkUriMap[artworkUri] = notificationBuilder
loadImage(artworkUri)
} else {
notificationBuilder.setLargeIcon(
BitmapFactory.decodeResource(mService.resources, R.drawable.itunes)
)
}
val notification = notificationBuilder.build()
mNotificationManager?.notify(NOTIFICATION_ID, notification)
return notification
}
private fun loadImage(uri: Uri) {
albumArtFutureTarget?.cancel(true)
albumArtFutureTarget = Glide.with(this.mService.baseContext)
.asBitmap()
.load(uri)
.override(512, 512)
.placeholder(R.drawable.itunes)
.listener(object : RequestListener {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target, isFirstResource: Boolean): Boolean {
val notificationBuilder = artworkUriMap[model]
notificationBuilder?.setLargeIcon(
BitmapFactory.decodeResource(mService.resources, R.drawable.itunes)
)
mNotificationManager?.notify(NOTIFICATION_ID, notificationBuilder?.build())
return false
}
override fun onResourceReady(bitmap: Bitmap, model: Any, target: Target?, dataSource: com.bumptech.glide.load.DataSource, isFirstResource: Boolean): Boolean {
val notificationBuilder = artworkUriMap[model]
////===========HERE IS LOAD BITMAP===========
notificationBuilder?.setLargeIcon(bitmap)
mNotificationManager?.notify(NOTIFICATION_ID, notificationBuilder?.build())
return false
}
})
.submit()
}
SS-уведомление:
Подробнее здесь:
https://stackoverflow.com/questions/792 ... -pixilated
1732857117
Anonymous
Я создаю уведомление и устанавливаю большой значок в конструкторе, используя растровое изображение. Я отлаживаю это растровое изображение, оно становится правильным с размером 1024*1024, но все равно после добавления в уведомление оно показывает мне пиксельное (размытое) [code] notificationBuilder?.setLargeIcon(bitmap) // using this we load bitmap you can check in below code [/code] Вот код для создания уведомления [code]fun generateNotification(isPlaying: Boolean? = null): Notification { val notificationBuilder = NotificationCompat.Builder(mService, CHANNEL_ID) createNotificationChannel() notificationBuilder.setStyle(style) notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH) mediaSession.isActive = true val state = if (isPlaying == true) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED playbackStateBuilder.setState(state, mService.getCurrentPosition(), mService.getPlaybackSpeed()) val playBackState = playbackStateBuilder.build() mediaSession.setPlaybackState(playBackState) mediaSession.setCallback(callback) val mediaMetadataBuilder = MediaMetadataCompat.Builder() mediaMetadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mService.getDuration()) mediaSession.setMetadata(mediaMetadataBuilder.build()) notificationBuilder.setContentIntent(mContentIntent) notificationBuilder.setSmallIcon(R.drawable.itunes) .setContentTitle(mService.getCurrentMediaItem()?.mediaMetadata?.albumTitle ?: "") .setContentText("${mService.getCurrentMediaItem()?.mediaMetadata?.subtitle} Episodes") .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_TRANSPORT) val artworkUri = mService.getCurrentMediaItem()?.mediaMetadata?.artworkUri if (artworkUri != null) { artworkUriMap[artworkUri] = notificationBuilder loadImage(artworkUri) } else { notificationBuilder.setLargeIcon( BitmapFactory.decodeResource(mService.resources, R.drawable.itunes) ) } val notification = notificationBuilder.build() mNotificationManager?.notify(NOTIFICATION_ID, notification) return notification } private fun loadImage(uri: Uri) { albumArtFutureTarget?.cancel(true) albumArtFutureTarget = Glide.with(this.mService.baseContext) .asBitmap() .load(uri) .override(512, 512) .placeholder(R.drawable.itunes) .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target, isFirstResource: Boolean): Boolean { val notificationBuilder = artworkUriMap[model] notificationBuilder?.setLargeIcon( BitmapFactory.decodeResource(mService.resources, R.drawable.itunes) ) mNotificationManager?.notify(NOTIFICATION_ID, notificationBuilder?.build()) return false } override fun onResourceReady(bitmap: Bitmap, model: Any, target: Target?, dataSource: com.bumptech.glide.load.DataSource, isFirstResource: Boolean): Boolean { val notificationBuilder = artworkUriMap[model] ////===========HERE IS LOAD BITMAP=========== notificationBuilder?.setLargeIcon(bitmap) mNotificationManager?.notify(NOTIFICATION_ID, notificationBuilder?.build()) return false } }) .submit() } [/code] SS-уведомление: [img]https://i.sstatic.net/ZnJFDamS. png[/img] Подробнее здесь: [url]https://stackoverflow.com/questions/79235912/android-notificationbuilder-large-icon-getting-pixilated[/url]