Clearing OnGoing Notifcations From My Application - android

I have multiple notifications from my application and the notifications are set to ongoing notification. I want to clear the notification when addaction performs on particular notification.
I can't know the notification id because these are set dynamically. can

Related

Removing specific notification when you don't know the notification id?

How can I remove a specific notification when I don't know the notification id (when app was not running and OS generated the notifications)? I don't want to use notificationManager.cancelAll() because there are multiple types of notifications and I can't use notificationManager.cancel(id) because I don't know the ID of that notification.
I've already gone through most of the SO threads so please don't mark it as a duplicate of the following:
How to clear a notification in Android
How to remove an android push notification from notification center when the app gets started by its launcher icon?
How to remove push notifications that have already been sent?
How to remove an android push notification from notification center when the app gets started by its launcher icon?

How the android application knows when the heads up notification disappears?

We need to display the heads up notification when our application receives a notification and application is running in foreground. If application receives any other notifications while the current notification is in display, we need to queue the notifications, pop it from the queue and display it when the current notification disappears. Since the heads up notification automatically disappears from screen (remains visible in the notification drawer), I am not sure how our application knows when the heads up notification disappears from screen. Is there any event our application receives? Can any one please let me know if there is any mechanism to know when the heads up notification disappears?

Push notification received while the app is in the foreground is different from push notification received when the app is in background

I have implemented FCM push notifications in an android app.
While I am logged in to the app. I get the notification in the form that I am expecting as below.
When the app is in background I receive the json response instead as below.
Following is the code I have added in onMessageRecieved()
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("App")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap))/*Notification with Image*/;
How can I get the notification in the same manner in both cases.
Any help will be appreciated thank you
After setting up FCM in Android application, you can use Firebase console to send notifications. When foregrounded application receives a notification, onMessageReceived method is invoked. You should override this method to handle notification, but the problem is when the application is in the background and receives a notification, notification delivers to the device’s system tray and you can not handle notification with onMessageReceived method. When the user taps on a notification, it opens the app launcher by default. For example consider you want to do a specific task when a notification is received to the user or do something in background without the user realizing or don’t want to show notification dialog to the user, you can’t do these when the application is backgrounded.
Message Types
With FCM you can send two types of messages to clients :
1- Notification message, sometimes thought of a “display message”
2- Data message, which are handled by the client application
According to Google documents a notification message has a 2KB limit and a predefined user-visible keys. Data messages let developers send up to 4KB custom key-value pairs.
Solution:
If you want to handle notification when the application is backgrounded you should send data message and use onMessageReceived method.
Here is the complete article.
That is so because push notifications handles in foreground and background in different ways.
From the documentation
Notification messages delivered when your app is in the background. In
this case, the notification is delivered to the device’s system tray.
A user tap on a notification opens the app launcher by default.
Messages with both notification and data payload, both background and
foreground. In this case, the notification is delivered to the
device’s system tray, and the data payload is delivered in the extras
of the intent of your launcher Activity.
Also you have to remember that there are 2 types of firebase pushes - Notification message and Data message.
Looks like you are using Notification messages, so they are working as expected.
Just use data type of messages and so you can always handle them as you need.

How to handle click event on notification in android (FCM) when app is in background or killed?

I am trying to handle a click operation on notification when application is
in background or killed, for redirecting application to notification details screen. I can handle it when there is only one notification in the Notification tray by using the Default Activity defined in manifest file.
But the problem is when there are two or more notifications in the Notification tray, how i can identify which notification is clicked..?
Please help

Android System Tray Notification Handling via FCM

I am sending notification and data payload from my server and generating a notification in Android System tray. but if I want to remove particular notification if user read that conversation through app and not via clicking system tray item then how to find that notificationId to write code like notificationManager.Cancel(notificationId) and not notificationManager.CancelAll()

Categories

Resources