I would like to use some images to show the weather in my notification.
My code is -
Bitmap largeIcon = BitmapFactory.decodeResource(thisContext.getResources(), R.mipmap.logo);
// Create a notification and set the notification channel.
Notification.Builder notification = new Notification.Builder(thisContext, id)
.setContentIntent(pendingIntent)
.setColorized(true)
.setColor(notiColour)
.setContentTitle("Weather Warnings!")
.setContentText(warningText)
.setLargeIcon(largeIcon)
.setSmallIcon(icon)
.setStyle(new Notification.BigTextStyle()
.bigText(warningText))
.setChannelId(id)
.setAutoCancel(true);
// Issue the notification.
notificationManager.notify(notificationID, notification.build());
I have a 512 x 512 bmp image, and the notification looks like this -
I have tried making the image smaller, but then there is no image (or perhaps only a white part of it)
The image I'm trying to use on this occasion is -
What have I done wrong?
Thanks!
(If you want to downvote, please at least comment so I learn what I have done wrong. I've been looking for an answer for an hour or so, with no joy. I believe my question is formatted correctly. Thanks)
EDIT So I've tried this code, but it seems to have just pixelated it -
BitmapDrawable largeIconDrawable = new BitmapDrawable(thisContext.getResources(), BitmapFactory.decodeResource(thisContext.getResources(), R.mipmap.logo));
Bitmap largeIcon = largeIconDrawable.getBitmap();
Resources res = thisContext.getResources();
int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false);