How can I clear firebase cloud message notifications? - firebase

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.

Related

Handle Notification data without click on notification in ionic 3 (One signal push notification)

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

How can I find out about notification delivery (ti.goosh)

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.

background push notification in ionic3

I have completed an e-commerce app in ionic3. The problem is I want user to be notified when new offers or deals are added in our inventory. This should be a backend process, whether or not the app is open or close.
Note: There is no firebase involved.
If you want to use to get notification in same device then you can try Local notification native plugin for notification and if you want to send notification to other device then you have to use Push or FCM or Onesignal and yes this all required firebase to send push notification to generate device id/key.

Flutter FCM Push Notification Not Working when app is in foreground

I am sending push notifications using Flutter's firebase_messaging package and I send them in the firebase console. When the app is in the background or when it is closed, I am receiving the notifications, however, when the app is in the foreground it is not working. Please tell me if I need to integrate Javascript to make this feature work, and please reference a resource that I can use in order to figure out how I can integrate Javascript with fcm as I haven't found a way to do this with flutter.
I figured out that someone can use the flutter local notifications plugin so that when the push notification is sent and the app is on the foreground, normally no notification would be delivered to the system tray, but using the flutter local notifications plugin, it would be possible to send a local notification when the app is on the foreground.
To Understand better.
Have a look into this table.
https://pub.dev/packages/firebase_messaging#receiving-messages
It states that when your Android or iOS Application is in foreground, OnMessage callback is called if you are sending notification payload or data payload as notification body.
You are receiving notifications when your app is in background because, when an app is in background notification is send to system tray and OS (Android or iOS) handle it for you. And your app is launched when you click on notification from system tray.
When your app is in foreground you have to catch notification payload in onMessage and handle it explicitly, you can create local notification in this case.

How to fix Firebase notification issue while in background mode

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

Resources