I made a Cloud Function that sends FCM messages, and is written in Python. The JSON is configured as follows... But I'am not surse how to set message.android.priority
and message.android.notification.notification_priority
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
message.android.priority
: They say that this is an enum type, but in the examples on the website they use a string "normal" or "high". And then, type use lowercase although in the docs they say Enum: "NORMAL", "HIGH" - with uppercase.
message.android.notification.notification_priority
: This is an Enum also, with "PRIORITY_DEFAULT", "PRIORITY_HIGH", an so on...
How to set an Enum in a JSON ? As a string ? And if so, does character case matters ?
I don't understand what is the type of the enum items on these two keys values... Is it string like "HIGH" and "NORMAL", or some integer constants ?
And a secondary question... What should I set so that my FCM message is delivered right away even when the phone screen is closed, and notify the user with sound ?
# Construct the message payload message = { 'message': { 'token': app_token, 'android': { 'priority': 'high', 'notification': { 'title': msg_title, 'body' : msg_body, 'icon' : 'ic_app_mono', 'color': '#FF0000', 'sound': 'default', 'notification_priority': 'PRIORITY_DEFAULT' }} }} # Use ADC to get the credentials credentials = default()[0] # Send the message result = SendMessage(credentials, message)
The key is notification_priority
and the value must be one of enum
NotificationPriority
:
PRIORITY_UNSPECIFIED
, PRIORITY_MIN
, PRIORITY_LOW
, PRIORITY_DEFAULT
, PRIORITY_HIGH
, PRIORITY_MAX
... on the sending side.
The equivalent on Android (locally) would be NotificationManager.IMPORTANCE_*
. It does not really matter how "important" a notification is, it only matters what is being set, when passing it to NotificationManager
... on the receiving side.