Issue
My app has an option to turn on/off FCM notifications.
I can not show FCM notification when the App in foreground.
But how to turn off the notification function of FCM when the App in background?
Turn off FCM functionality with code in Android Studio.
Solution
Firebase Cloud Messaging has two payload types in its messages:
- Notification payloads, which is handled by the system itself if the app is not active, and can be handled by your code if the app is active.
- Data payloads, which are always handled by your code. This code can then display a notification, but it can also do something else (or nothing at all) with the data.
If you send a Notification message and the app is not actively being used, that message is handled by the system and there's no way to prevent it from being displayed.
So you have two options:
Always send message with (only) a data payload, so that your own code can handle it - and display a notification if the user hasn't disabled that.
Don't send a message with a notification payload if the user has disabled receiving notifications.
Answered By - Frank van Puffelen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.