When my Ionic app is in foreground, notification arrives perfectly.
When my Ionic app is in background, the Firebase push notification displays the a system tray notification. Pressing the banner opens the app and the notification fires. I am completely fine with that.
But, if user decides to open the app without clicking the banner, the notification doesn't trigger. Anytime clicking the banner results into the arrival of the notification into the app.
How can I resolve this situation? How can I make the notification fire, regardless of whether the app is clicked from notification tray or normally?
Edit:
The firebase data message I'm sending looks like this :
{
"data":{
"fieldA":"A",
"fieldB" : "B",
"fieldC" : "C",
"total" : 1234,
"title" : "_my_title",
"message" : "_my_message",
"sound" : "default",
"cick_action": "FCM_PLUGIN_ACTIVITY"
},
"to":"/topics/MY_TOPIC",
"priority":"high"
}
Make sure the notification you send is of type data message, not display messages.
With FCM, you can send two types of messages to clients:
Notification messages, sometimes thought of as "display messages."
These are handled by the FCM SDK automatically.
Data messages, which
are handled by the client app.
https://firebase.google.com/docs/cloud-messaging/concept-options
Also
When in the background, apps receive the notification payload in the
notification tray, and only handle the data payload when the user taps
on the notification. When in the foreground, your app receives a
message object with both payloads available.
And
To receive messages, use a service that extends
FirebaseMessagingService. Your service should override the
onMessageReceived and onDeletedMessages callbacks.
https://firebase.google.com/docs/cloud-messaging/android/receive
Related
i am using Onesignal in ionic 3. I am getting notification properly when the app is in foreground. When I receive a notification in background i am getting the data in the notification only after tapping the notification. But i want to get the data without tapping on the notification.
You're looking for Silent Notifications (Silent Notifications are background notifications that do not show any message on the device)
Right now, you're likely using the onOpened handler. You will need to set up a service extension and be prepared to have to write native code!
https://documentation.onesignal.com/docs/silent-notifications
I use Appcelerator Titanium and I have module ti.goosh for push notification. How can I find out about notification delivery? In 'callback' I can find out about opening the notification, but I want to also know that the notification is in the device tray (for example using console.log).
I depends on what kind of message you are sending. A FCM data message is handled by the module with the NotificationCompat.Builder but if you are sending a normal FCM notification message the system is creating the notification and displaying it. You will only know if the notification was clicked by the user (like you already do) or if it arrived while the app was in foreground.
I had read that not to add notification node in the body of the request, and I tried to send without notification node but it seems that the message not received but when I add the notification node it work well
So, what is the difference notification node and data node in Firebase cloud messaging?
{
"to": "/topics/some_topic",
"data": {
"key_1" : "some_value",
"key_2" : "some_value"
},
"notification":{
"body" : "some_message"
}
}
Is there any link to doc I can read ?
The data node is used for sending notification if the application is on the background/foreground and in some phones if it is also killed.
The notification node is used for sending notification if the application is on the foreground. If it is in the background you wont receive the notification.
The best option I found is to use data node alone.
Also it is explained very well in this link: The FCM messages types
Notification node (a.k.a Notification messages)
When sent, this will receive a notification on the device, regardless of whether the app is in foreground/background/terminated state, but the notification will be shown only when the app is not in foreground. You can bundle a data payload with this of upto 4 KB. The upside is that you do not have to worry about generating a notification every time, the libraries take care of that. The downside is that there is no way not to show the notifications, for eg when you want to do something silently.
Data node (a.k.a Data messages)
When sent, this will fire up all the same callbacks as a normal notification node would, the only difference being that a notification won't pop up on its own, you are the master of your own callback! This is useful for when you want to do something silently, like refresh the cache, update the database etc. As a data node will have the data payload and will fire up a callback at any state of the app, you can generate a notification on your own and fire it up. This gives you the freedom to design your notification however you want!
I use firebase cloud message to send messages to my phone, and I can successfully receive notifications. But in some cases, I do not click notifications to open my app, but manually open the app to go into foregroud. And what I want is when I open the app, notifications in notification bar should be automatically cleared.
The following code will clear all notifications for your app, including those created by FCM. You could add this to the onResume method of your main activity:
NotificationManager manager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancelAll();
Usually you would cancel a notification by specifying the ID you gave it when it was created, however as FCM is creating the notification for you, you can't know its ID, and so must cancel it by cancelling all notifications as above.
I have created an app, used the client/api keys in my android app to subscribe to a channel. I can see my device on the core/installations page but on the send push page, clicking on the send a push button doesn't do anything. Instead I see the message "No push notifications to display yet." and a button "learn how to send push notifications". I have to add that this is not my first app but a new one. What has changed?