0

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 -

enter image description here

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 -

enter image description here

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);
AndyCr15
  • 465
  • 5
  • 17
  • probably you are setting your image in imageView and setting imageview width and height to wrap_content will get you this because image size is quite large. So if you want to fix the size just give custom size to imageview and you will be good. And I didn't do the downvote ;) – Umair Nov 08 '17 at 09:23
  • Thanks, for the comment and thanks for not downvoting ;-) I don't quite understand though, where in my code am I setting anything to do with an imageview? (Or where can I perhaps?) – AndyCr15 Nov 08 '17 at 09:47
  • Oh sorry i didn't saw your code . ok you have to use notification_large_icon_height and width parameter to resize your image. Take a look at this question. https://stackoverflow.com/questions/7220738/honeycomb-notifications-how-to-set-largeicon-to-the-right-size – Umair Nov 08 '17 at 10:01
  • and additionally you should go through android different sizes for different screens take a look at this https://stackoverflow.com/questions/25030710/gcm-push-notification-large-icon-size – Umair Nov 08 '17 at 10:02
  • Using the first link I've tried some new code, which I thought would resize it, but it doesn't seemed to have worked :-( (I've edited in the new code to my question if you want to see) – AndyCr15 Nov 08 '17 at 10:49

0 Answers0