I'm using NotificationListenerService to read the notifications posted by other apps. In onNotificationPosted I get the deleteIntent of the notification and call deleteIntent.send() to remove the notification. This doesn't work for notifications posted by some apps! I have tried removing them using cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()), but this also fails to remove them.
When swiping a notification on a phone or on a watch removes the notification from the phone, I expect firing deleteIntent explicitly, remove the notification as well.
Any ideas on why some notifications can't be removed?
The FLAG_NO_CLEAR has been set which prevents the notification from being cancelled.
Related
I'm using Google Cloud Messaging to receive new orders into an app. I'm trying to handle cases where the same order is sent twice. I just want the second receipt to be ignored, unfortuntately when the app is in the background I dont seem to be able to cancel the notification (ie it still makes a noise and sends a message). The app works fine when in the foreground, putting cancel notification code in my GCMBrodacastreceiver doesnt seem to do anything. Am I missing something?
NotificationManager mNotify = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotify.cancelAll();
You can set the "tag" field in the notification payload. If you use this the incoming notification will just update any existing one with the same tag.
cancelAll() will dismiss the notification, but your code may not be invoked when the app is in the background as the notification will be posted without your app's code running. One option would be to have your server not send the notification if it has already sent one recently.
i'm building an ongoing notification in my app.
I didn't found how to prevent it from being sent to wear.
i thought that ongoing notification were not sent but my notification is sent anymay. (i have used mBuilder.setOngoing(true);)
Anybody has an idea ?
In the Notification.Builder class you have a "setLocalOnly" method that allows you to configure this.
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 there any way to clear notifications from Notification Tray all(including third party applications also).
how can i achieve this functionality can u please help me.
Thank you
From this.
The user clicks the notification, and you called setAutoCancel() when
you created the notification.
You call cancel() for a specific
notification ID. This method also deletes ongoing notifications.
You
call cancelAll(), which removes all of the notifications you
previously issued.
Note: You can't cancel notifications from other apps - its done that way to prevent malicious apps from hiding other applications.
I want to clear all the notification present in my device, notifications from other apps also.
I tried using:
mNotificationManager = (NotificationManager) getSystemService(TestActivity.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
but of no good. Whereas in another test from where i am sending notifications this code works.
Is it not permitted to delete notifications from other applications ?
You can't cancel notifications from other apps- its done that way to prevent malicious apps from hiding other applications.