How to send actions with Firebase push notifications?

Stesvis 1,041 Reputation points
2021-08-16T19:31:42.07+00:00

I am implementing push notifications in my app, using these packages:

What I don't understand, and I can't figure out, is how to display push notifications with actions.
For example, this is what I mean:
123668-image.png

If I can learn how to send a notification with action(s), then I can handle the events with the FirebasePushNotificationPlugin in this way:

   // Push message action tapped event  
   CrossFirebasePushNotification.Current.OnNotificationAction += Current_OnNotificationAction;  
     
   private void Current_OnNotificationAction(object source, FirebasePushNotificationResponseEventArgs e)  
   {  
   	if (!string.IsNullOrEmpty(e.Identifier))  
   	{  
   		System.Diagnostics.Debug.WriteLine($"ActionId: {e.Identifier}");  
   		foreach (var data in e.Data)  
   		{  
   			System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");  
   		}  
   	}  
   }  

Does anybody have experience with Firebase Admin or with sending action? Thanks!

Developer technologies | .NET | Xamarin
{count} votes

Accepted answer
  1. Stesvis 1,041 Reputation points
    2021-08-18T18:02:01.637+00:00

    Thanks @Anonymous yes that's where i got my snippets from too but i couldn't get it to work when I send the payloads with FirebaseAdmin.
    But i think i resolved it finally.

    These are the expected payloads:

    124379-image.png

    And with FirebaseAdmin I was sending the data field and the notification field together in the same payload because i had some iOS and some android devices in the list.
    I learned that if i do that it creates a conflict (even tho the notifications are received).

    The solution is to send two different payloads, one to only iOS devices and one to only android devices and everything works and the buttons show up.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.