Add Action To Firebase Notification

10,077

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.

Share:
10,077
MayaB
Author by

MayaB

Updated on June 11, 2022

Comments

  • MayaB
    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
    MayaB over 7 years
    Thanks 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
    MayaB over 7 years
    Thank 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
    Rohit Bandil almost 7 years
    Can you more specific on that adding data key or only data key in notification payload?