TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

Action Buttons on the Push Notification #100

Closed omxie closed 1 year ago

omxie commented 1 year ago

Hi there,

I am trying to send a notification to the device with 3 action buttons and perform certain tasks on click of those buttons. Is it possible to use the plugin to do so? or does it have to be implemented something natively.

Thanks!

TobiasBuchholz commented 1 year ago

For android you can change the appearance of the default push notification and therefore add your 3 action buttons by setting the static NotificationBuilderProvider Func of the android FirebaseCloudMessagingImplementation class:

...
    FirebaseCloudMessagingImplementation.NotificationBuilderProvider = CreateNotificationBuilder;
...

private static NotificationCompat.Builder CreateNotificationBuilder(FCMNotification notification)
{
    return new NotificationCompat.Builder(_context, ChannelId)
        .SetSmallIcon(Resource.Drawable.ic_push)
        .TrySetBigPictureStyle(notification)
        .SetContentTitle(notification.Title)
        .SetContentText(notification.Body)
        .SetPriority(NotificationCompat.PriorityDefault)
        .SetAutoCancel(true);
}

For iOS I think you'll need to add an iOS extension project to customize your push notifications. Last time I checked this wasn't possible for .NET MAUI applications yet, but maybe it's now. If you are successful implementing it that way, please let us now :)