How do I clear all notifications with separate app? - android

Is it possible to make an icon on android that when clicked clears all notifications, e.g. SMS, email, missed calls etc?
I just want an icon on my home screen that clears all notifications. What coding would I use?

cancel(notificationID) where you pass the notification id of the notification you have created
or else, you can clear all your notifications by cancelAll().
*NOTE : * Only notifications created by your application can be deleted. You cannot remove notifications created by some other application.

You can only remove a Notification that you raise yourself. You cannot remove a Notification raised by another application.

Related

Persistent Notification Message with switch (ON/OFF) on Android/iOS?

I have a mobile app implemented in React Native where the user has a status online/offline. I want to implement a persistent notification message that shows up whenever the user status is Online, even if the app in the background.
I know that there is a possibility to do actions within notifications like pause button in the media player apps. How could this be done in react-native?
Use https://github.com/zo0r/react-native-push-notification
If you want to make it sticky you can set :
PushNotification.localNotification({
ongoing:true
)}
You can use ongoing property of this library to make sticky notification
I'd look into https://github.com/testshallpass/react-native-dropdownalert I think it would offer exactly what you need
You can use FCM for push notification.
Package details :
https://github.com/evollu/react-native-fcm
First you need to store user vise device token into your database. Then if user's status changes to online you can send FCM notification to set of device tokens or just one you set. So notification will pop on your device.
Hope this is what your are looking for.

Show only notification with multi application when call push from server

I created two applications and installed them on a device. Both apps have the same notification id. Whenever I send a push notification from my service, two notification show up.
I want to show only one notification (instead of displaying the same notification twice). Can I do it? If so then how can I do it?
You can use a shared preferences between the two apps and write a value when some app show the notification. Then just before to show it you should check the shared preferences to know if the other application has shown the notification or not. Even you can add delay in one of the applications giving preference to the other one.

In Android how do I get the currently displayed notification for a given notification id?

My intention is to display a notification with a personalised icon. However, if a notification with the same id is already displayed and then I need to add a new notification with the same id, my program will instead prepare a "stacked" version of the notification where the icon is changed to some generic icon and the notification content shows excerpts from the last and current notifications. Similar to how Gmail does when there are multiple emails.
To implement that I need to check if there are notifications of my app, currently displayed. I do not see any API to retrieve my own notifications.
I cannot simply cache the notification details that I have displayed till now, since in that case I need to know when they will be dismissed by the user, and update my cache accordingly. I also do not see any API to listen for dismiss events.
If you observe the gmail app notification behaviour properly u will notice that even when u dismiss one notification gmail shows you the same notification again in the list when a new notification comes. It looks to me that gmail is relying on total unread/unopened messages rather than keeping a cache of notifications.
There is no direct api for ur suggested SDK version. You need to fallback to ur own implementation. However, there is a way to know if a already showed notification was dismissed - How to know when my notification is cleared via Clear button?
This is possible with android 4.3 upwards now
See http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications()

How to clear all notifications from Notification Tray in android

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.

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.

Categories

Resources