thomasgalliker / Plugin.FirebasePushNotifications

Receive and handle firebase push notifications in .NET MAUI apps
MIT License
66 stars 5 forks source link

Firebase.CloudMessaging Android: Allow notification images to be shown as a large icon, but not as a big picture. #43

Closed scottjodoin closed 3 months ago

scottjodoin commented 4 months ago

Summary

Android: Allow notification images to be shown as a large icon, but not as a big picture.

API Changes

According to this documentation, it is possible to just set the large icon without an expandable big picture. https://developer.android.com/develop/ui/views/notifications/expanded

This code inside Plugin.Firebase.CloudMessaging.Platforms.Android.Extensions; public static class NotificationBuilderExtensions has

public static class NotificationBuilderExtensions
{
    public static NotificationCompat.Builder TrySetBigPictureStyle(this NotificationCompat.Builder @this, FCMNotification notification)
    {
        try
        {
            if (Uri.IsWellFormedUriString(notification.ImageUrl, UriKind.Absolute))
            {
                Bitmap bitmap = DecodeBitmap(notification.ImageUrl);
                return @this.SetLargeIcon(bitmap).SetStyle(new NotificationCompat.BigPictureStyle().BigPicture(bitmap).BigLargeIcon((Bitmap?)null));
            }

            return @this;
        }
        catch (Exception ex)
        {
            Console.WriteLine("[Plugin.Firebase]: Couldn't attach image to push notification: " + ex.Message);
            return @this;
        }
    }

I would like to be able to set it so that the SetStyle function is not called.

Intended Use Case

I would like to be use the image url sent via firebase to represent a profile picture, etc. like facebook messenger and not have it expandable as an image.

scottjodoin commented 3 months ago

Thank you!

thomasgalliker commented 3 months ago

Ups, I wanted to ask you if it works. But I guess it does 👍🏻

scottjodoin commented 3 months ago

I haven't been able to test it yet. I was looking through the code to see how to set the settings and I could find it. As a user o this package, how can I set the notification style?

thomasgalliker commented 3 months ago

Ok. If you find some time, I would appreciate your feedback.

Regarding notification styles: I‘m not very familiar with those. I just read the documentation. Until now, BigTextStyle is used by default (but you can opt out via specific data key or Android option). Furtermore, I think the big image style is also available (I have to look at the code again).

Generally, all kind of styles could be made available. If you‘re missing a specific one, csn you open a new issue?