Android Wear Notification Dismissed Listener - android

Has anybody found a way to trigger a callback/listener when a notification has been dismissed? Or any way to send a message or alter a data item on dismiss?
It seems to me this would be helpful for collecting analytics, but I haven't found a mechanism that allows for it.

NotificationCompat.Builder.setDeleteIntent (or the equivalent in Notification.Builder if you are doing local notifications on the Android Wear device) allows you to set a PendingIntent that will be called when your notification is dismissed.

Related

Choose to show or ignore push notifications client side?

We want to send push notifications in Android and iOS to a group of users that match a certain condition. We can check if an user match this condition calling an API.
Our problem is that the users information changes very quickly and we don't have any way to keep track of this in our push notifications engine (OneSignal).
The only alternative we can think is to send the push notification to all users and client side call the API to get the latest user information. Depending on this we could choose to show the notification or ignore it.
Is this possible on Android and iOS?
It is 100% possible for sure. in the receiver class you call an intentservice, which can hit an api and get the latest information, based on the information you create notification using notification builder, and avoid if you dont want.
Yes, with the help of NotificationExtenderService this is possible.
Receive a notification in the background. Notification data is wrapped up in OSNotificationReceivedResult object. Now, read the notification id/title which should be unique for every notification.
Send this unique notification title/id along with user id to an API, which will return whether to show the notification to the user or not. If true then read notification title and message/description from OSNotificationReceivedResult and make a notification via NotificationCompat otherwise just ignore it.
Reference

Stacking push notifications in Delphi to Android application

In my delphi code app, Is possible I change the settings of my pending intent used to handle push notifications when It arrives? I´d like to change your behaviour. Instead I have many push icons notifiactions on status bar when each new push messages arrive, I´d like to have only one with a counter increasing when new push messsages arrive. I´d like something as https://developer.android.com/training/wearables/notifications/stacks.html
Luiz
You can implement the logic you want.
When you receive a push, it carries various data.
If a notification is already displaying such data, you can cancel the existing notification and create a new one.
In any way, the notification manager of android will be able to stack notifications by itself for you.
So i suggest, when you receive data from a push:
Store it to sqlite
Calculate the notification ID you need to display that notification (can be a hashCode of the notification type ?)
Fetch all notif for that type from sqlite
Cancel the notification with this ID (don't worry, cancelling a non existing notification won't make your app crash)
Create a shiny new notification with all the data you fetched, if you have more than one, you might want to display "+X other".
EDIT: With my answer, i assumed you can do as much as thing in "delphi to android" than in native android. Hence, i can't provide code for you, but the idea does not depend of the language you are using.

How to know if an notification has been cancelled?

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 .

how to impliment Notifications aggregation

My application displays event notifications, and I'm looking for a way to have notification aggregation.
Meaning, I would like to show 4 notification, but if the fifth comes, I would like to collect all notifications and show only one general notification.
Os there a way to know how many live notifications i have?
Is it possible to approach these notification and cancel them?
Thanks!
According to the android design guidelines you should stack your notifications. So you should avoid showing multiple notification for the same app.
You can stack your notifications using
NotificationManager.notify(ID, notification) where you specify same ID for each notification.
You can check the docs on how to implement it.
For your case
Is there a way to know how many live notifications i have - No
But you can keep a track of the notifications using Shared Preferences, where you store the ID of the notificaion and remove it when the user clicks on the notificaion
Is it possible to approach these notification and cancel them? - Yes
You can cancel a notification using the cancel(int id) method, where you pass the ID of the notification to be removed.
So you can use this method to acheive what you want, but it advisable to stack all the notifications.

Get all existing notifications from system tray

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

Categories

Resources