MAUI 8 Handle Firebase Cloud Message when app is in background

35 Views Asked by At

I'm trying to customize notification send by Firebase Cloud Messaging when application is not started. I just want to modify the sound of the Notification. I'm using FirebaseAdmin on the Back End to send the Notification and Plugin.Firebase on MAUI 8 App to register and handle notifications.

This is how I'm sending Notification:

            await FirebaseMessaging.DefaultInstance.SendAsync(new Message()
            {
                Token = fcmtoken,
                Notification = new Notification()
                {
                    Title = title,
                    Body = body
                }
            });

This is how I handle the Notification in MAUI 8 App:

            FirebaseCloudMessagingImplementation.ShowLocalNotificationAction = notification =>
            {
                var intent = PackageManager.GetLaunchIntentForPackage(PackageName);
                intent.PutExtra(FirebaseCloudMessagingImplementation.IntentKeyFCMNotification, notification.ToBundle());
                intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Immutable | PendingIntentFlags.UpdateCurrent);
                var builder = new NotificationCompat.Builder(this, channelId)
                    .SetSmallIcon(Android.Resource.Drawable.SymDefAppIcon)
                    .SetContentTitle(notification.Title)
                    .SetContentText(notification.Body)
                    .SetPriority(NotificationCompat.PriorityDefault)
                    .SetAutoCancel(true);
                System.Diagnostics.Process.GetCurrentProcess().CloseMainWindow();
                var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                notificationManager.Notify(123, builder.SetContentIntent(pendingIntent).Build());
            };

The problem is that, when my application is running I'm receiving the Notification by the "NotificationChannel" what I created and I'm able to customize. But when the application is not started the Notification is delivered by different "NotificationChannel" created I believe by Google Services. Is there a way to override somehow the behavior of the Notification when the application is not started?

0

There are 0 best solutions below