Is there a way to get the list of notifications of my app?
I need to list them and let the user to delete them one by one, but I can't find a way.
I don't believe that you can list your notifications that have been shown. If the user wants to clear a notification from the app then all they need to do is pull the notification draw down and swipe it away. You can have your app cancel a notification using the NotificationManager by supplying the id of your notification to the cancel method.
If the use clicks the notification you then have two options for clearing.
1) When creating the notification you can call Notification#setAutoCancel(true) and the notification will be automatically cleared when the user taps on it.
2) Pass the notification id as part of the PendingIntent with the notification then you can use this to cancel the notification when the user taps on it.
Related
Is there a way to know that a user has clicked on a notification when the application is in the foreground?
I need to send analytics for when users click on the notification and I need to know when they have clicked it.
I can't put the analytics in the destination activity as I have other analytics that are sent when the user gets to that screen. I need to know that a user has specifically clicked on the notification to open the destination activity.
For example is there a callback for when a user clicks on the notification?
Thank you
you should .setContentIntent(pendingIntent) in NotificationCompat.Builder
and put into this intent variable, then, on app start, you should check if this variable exists in intent of destination activity and if it is true, send analytics
if it is what you want, i can give code sample
I'm building an Android app which creates notifications. Each notification has a number of additional actions.
The default application (when the user taps on the notification) launches an activity in my app. That's working fine.
When the user swipes the notification to dismiss the notification, my app responds by doing some deletion work, and the user is left on the list of notifications. The one that the user swiped is removed from the list.
For some of my additional actions I want to launch activities, and that's working fine; for the other actions, I want my app to do some work but I also want the user to remain on the notification list. I'm struggling to find a way to do this last part - all my attempts to configure the intent and pending intent for my additional action result in behaviour whereby when the user clicks on the action, the notification list disappears.
Is there any way to get what I want (i.e. a notification additional action which performs work but leaves the user on the notification list)? Do I need to build a custom notification layout or something?
My little app sends some notifications. We get a callback via a Pendingintent when the notification is clicked on. However, when a notification is simply removed without being clicked on, I don't get any kind of notification and thus wouldn't know if a notification has been removed by the user.
My ultimate goal is to limit the number of active notifications sent by my app to no more than 3. But I haven't been able to find a way to enumerate or simply get the count of active notifications sent by my app. The number of methods available in NotificationManager is rather limited.
Any help will be appreciated.
You can set a PendingIntent with setDeleteIntent() which will be called when the notification is removed from the notification tray (such as when the user swipes to dismiss it).
Do note that the notification design guidelines state:
If a notification of a certain type is already pending when your app tries to send a new notification of the same type, combine them into a single summary notification for the app. Do not create a new object.
A summary notification builds a summary description and allows the user to understand how many notifications of a particular kind are pending.
I.e., don't do this:
Do this (this example uses an InboxStyle notification as is recommended):
Make sure you are not posting multiple notifications of the same type.
the method "Notification.deleteIntent" you can use to set a PendingIntent which the notification was removed by system will be called .And then you can do something you want .
Is it possible for me to get all of the notifications from my app that's currently in the system tray?
I noticed we can update existing notifications that are already in the tray, but I am wondering if it's possible for me to retrieve all of them.
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating
Thanks
The short answer is "No", the Notification Manager does not provide a way to query the notifications currently in the tray.
If you want to keep track of your notifications in the tray, it is possible, but will take a little bit of work. You will need to create a way to track the status of your notifications, the easiest way is probably a database. What you do is insert a row for the notification, with that notification's id, when you create the notification. Next, you need to build an Activity or Service that will update your database with the status of your notification during its lifecycle. Before posting your notification to the manager, you need to add a contentIntent and a deleteIntent that route through the Activity or Service you just created. The contentIntent will be called when the user clicks the notification, and the deleteIntent will be called if the user dismisses it. When either of those happen, update your database to track the latest state!
If you implement that, you'll have a way to track your notifications, and their status in the tray. Unfortunately, there is no easy, readily available way to query them, especially if they're not of your creation.
Try this NotificationListenerService:
https://developer.android.com/reference/android/service/notification/NotificationListenerService
I have a background service setting up a notification in Android's status bar. The background service is doing some work, but needs to stop when the user clicks on or cancels the notification.
I am able to stop the service, if the user clicks on the notification by passing an intent to the notification when creating it.
Is it possible to react if the user cancels the notification? Or if all notifications are canceled? If so, how?
NB: I define cancel as removing the notification by swiping to the right on it, or clicking on the x at the top right to remove all the notifications.
Check out the deleteIntent of the Notification:
The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button.