Link to home
Start Free TrialLog in
Avatar of Ria jain
Ria jain

asked on

How to implement Firebase notification click event on Xamarin forms - android ?

I am using following code  ( but not clear how to pass a parameter when a user click on firebase notification? )

public override void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);
            string click_action = message.GetNotification().ClickAction;
            SendNotificatios(message.GetNotification().Body, message.GetNotification().Title, click_action);
        }
        public void SendNotificatios(string body, string Header, string click_action)
        {
            Notification.Builder builder = new Notification.Builder(this);
            builder.SetSmallIcon(Resource.Drawable.AppLauncher);
            //Intent intent = new Intent(this, typeof(MainActivity));
            Intent intent = new Intent(click_action);
            intent.PutExtra("click", click_action);
            intent.AddFlags(ActivityFlags.ClearTop);
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
            builder.SetContentIntent(pendingIntent);
            builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.AppLauncher));
            builder.SetContentTitle(Header);
            builder.SetContentText(body);
            builder.SetDefaults(NotificationDefaults.Sound);
            builder.SetAutoCancel(true);
            NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService);
            notificationManager.Notify(1, builder.Build());
        }

Open in new window

Avatar of Kyle Santos
Kyle Santos
Flag of United States of America image

Hi,

I am following up on your question.  Do you still need help?

If you solved the problem on your own, would you please post the solution here in case others have the same problem?

Regards,

Kyle Santos
Customer Relations
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.