Add Action To Firebase Notification
Solution 1
So in order to customize notifications when app is on background, as Diego mentioned, the only current way is to create the notification yourself. Adding "data" key to notification payload, results in onMessageReceived()
callback, on which you can create any notification andy notify.
Thing is, I tried to send a notification from Firebase console, rather then from the API. There I couldn't add the data key properly and catch it. From API all works fine.
Solution 2
firebase-cloud-messaging doesn't provide an API to add action buttons to the notifications.
You can request new features to the firebase library here: https://firebase.google.com/support/contact/bugs-features/
For now what you can do is to send a data-message
with a custom payload via the server-side API
You can then receive that payload in onMessageReceived() and generate your custom notification.
MayaB
Updated on June 11, 2022Comments
-
MayaB over 1 year
I'm trying to add an action button to notifications produced on firebase 9.0.0, for Android, when app is in background.
Any ideas?
Thanks!!
-
MayaB over 7 yearsThanks for the reply, Alexander! I'm trying to customize the notification itself, and add an action to it. However, click_action defines what should happen when clicking on the entire notification.
-
MayaB over 7 yearsThank you! my issue was that I tried to send the notification from Firebase console. adding "data" key didn't work for me that way...
-
Rohit Bandil almost 7 yearsCan you more specific on that adding data key or only data key in notification payload?