I have an android app which has a separate activity for notifications. I integrated firebase cloud messaging to my app for sending notifications to users. When I send a notification from the console, by default a notification pops up from the app. I want disable that notification and save the message from notification to a database. Later when user opens the app it gets the notifications data from the database and show them to the user. That means I don't want to show popup notifications to user, I want to show them only if user opens the app. My question is: How can I disable the default notification which pops up when a message is received?
If you want to send a message without a notification, you should not use the Firebase console to send that message. Instead, you will need to write some code on your desktop or backend, usually with the Firebase Admin SDK, to send a message with a data payload. The app will silently receive that message, and you can decide what to do with it from the callback you receive. Start with the instructions in the documentation to set up the client app. Be sure you are sending messages with only a data payload. It must not contain a notification payload.
Related
I am trying to send a push notification when user is going to uninstall my Android app. My idea is to use Firebase Cloud Messaging and Google Analytics for Firebase Triggers. In order to be able to use triggers I have been marked "app_remove" event as conversion in Firebase Console of my app. It is possible send notifications using Firebase Cloud Messaging triggered by a Firebase function as described in this question, but when my app is uninstalled It will not be able to show incoming message from FCM as a push notification. It is possible to setup the incoming message to be displayed as push notification even my app is uninstalled?
It is possible to setup the incoming message to be displayed as push notification even my app is uninstalled?
Not possible.
When your app is uninstalled, the corresponding registration token tied to that specific app instance is also invalidated.
The registration token is what FCM uses to send messages to the corresponding device, if invalidated, FCM will no longer have any way to send messages to that device.
I've implemented Firebase Cloud Messaging in my android app.
Is it possible to turn notifications off from my application settings screen?
It was possible with old GCM as we have broadcast GcmReceiver and we could handle it ourselves.
Now we have only FirebaseInstanceIdService and could handle it only when app is in foreground.
How we can handle it when app is in background?
Is it possible only to disable Firebase Cloud Messaging only for some category of notification inside app or this should be done on the server side?
You can manage whether or not notifications are displayed by always sending data messages from your app server. The Firebase console always sends notification messages, which are the types of messages that generate notifications automatically when your app is in the background. So if you want full control of when notifications are displayed use data messages which are only available from your app server, not yet from the Firebase console. See more on message types here.
I came with the solution to send request to the server if I need to switch on/off some type of notifications. And if send request to switch off some notification server will no longer trigger FCM server to send notification to the device
I can't get data payload when app is in background.
Unable to put custom notification on Status Bar. Please Help?
If you are using the Firebase console then no. If you send a message from the Firebase console and your app is in the background then any custom data will only be available through the notification. If the user never taps on the notification that accompanying data is lost.
If you want to send data to your application that is critical to its operation then you should send data messages, which you can do via the FCM REST API.
See more on the different types of messages in the docs.
I am trying to migrate to Firebase cloud messaging from GCM and I noticed that when the application is not running the notifications are coming in the notifications tray. With GCM this was not the case, it was up to the developer to show a notification or not. I want to have similar behavior with FCM where when the app is running I want to silently handle the push message instead of having user to click on the notification and start the app. How can I achieve that.
Thanks,
P
Firebase Cloud Messages has two types of messages:
Notification Message: this type of message has the same behavior as the GCM messages
FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys
Data Message: this type has the behavior you described above.
Client app is responsible for processing data messages.
Data messages have only custom key-value pairs.
To send data messages you need to use the HTTP API [for Data Message]. (quoted from Arthur)
Full documentation: https://firebase.google.com/docs/cloud-messaging/concept-options
Is it possible to send data payload through Firebase Console that we can receive in onMessageReceived() while our app is in background/killed?
It doesn't seem like the Firebase Console has the option to send "data" type messages. If you set the custom data fields in the Firebase Console, those will be delivered but only if your app is in the foreground. You need to implement your own FCM sender or use a 3rd party to send data type messages.
See this answer for more details about the two types of Firebase messages
Yes! but :)
When your application is in the background notification messages (which is what is sent from the console) are automatically displayed in the system tray. When the user taps on the notification the custom data is made available in the intent of the Activity that is launched.
Note that if the user never taps the notification there is no way to get at that data, so this data should not be critical for your application to function but should be used to enhance the user's experience once they have tapped the notification.
As you may have realised if your app is in the foreground, onMessageReceived is called and you can retrieve the custom data there.