I am using FCM in my app. I followed the Firebase documentation and all seems to be working as expected.
I am able to receive message notifications when the app is killed, in background and in foreground.
Now I want to give full control the user by adding some app preferences.
- The user can disable all notification from the app settings
- The user can change notification ringtone from the app settings
I have an idea on how to do it when the app is in killed or in the foreground. I am thinking of accessing the sharedprefs in my FirebaseMessagingService to see if the app should show the notification and check what ringtone to use. Unless there is a generic way to set those parameters, like "unsubscribing" from all notification or changing the app default notification ringtone which I am not aware of?
However I have no idea how i can do it for the notifications received when the app in is the background since the notifications are delivered to the device's system tray. Anyone has any idea or can point me to some documentation... I am not finding any info on this?
By default, notifications affect every user. If you'd like to allow users to opt-out of all notifications (or certain subsets of notifications), you should use topic messaging: by default, you'd call
subscribeToTopic()
for all users and if they opt-out of notifications, you'd callunsubscribeToTopic()
.By sending a notification to a topic, only the subscribed users will receive it.
The notification payload support documentation explains how to include a
sound
parameter to override the ringtone - on Android, that can be any sound bundled in the app'sres/raw
directory.It should be noted that neither of these features are supported in the Console, but require that you create your own Firebase Cloud Messaging Server