Reputation: 5840
I want to be able to get notifications before they are displayed to the user, save them and show them at some chosen time.
I tried the NotificationListenerService but i can only get the notification after it already displayed.
Is there any way to do it?
Also is there a way to block notifications from speciffic apps?
Upvotes: 0
Views: 140
Reputation: 8498
Update to @kiturk3 answer :
Also is there a way to block notifications from speciffic apps?
From Lollipop, this can be done. User can block notification from perticular package of application
Settings -> Sound and Notification -> Application Notification -> Click on any application -> Select Block
Furthermore, User can give Importance to specific application notification using priority
, while showing on Lockscreen
Upvotes: 0
Reputation: 558
I want to be able to get notifications before they are displayed to the user, save them and show them at some chosen time.
-> you can get notification that are arrived with onNotificationPosted(StatusBarNotification sbn)
you also can save them and you can show them at your desired time by creating a service and by building this notification again.
I tried the NotificationListenerService but i can only get the notification after it already displayed.
-> NotificationListenerService will give you notification information that are arriving. You can't block notification but you can remove the particular notification by getting its id or groupkey from notification stack.
Also is there a way to block notifications from speciffic apps?
-> No you can't block notification from arriving, though you can remove all notification, same way as i have mentioned above, which are not in your list of apps.
Edit All these can be done in API >=19 only.
Hope this Helps :)
Upvotes: 1
Reputation: 494
If you are using Google Cloud Messaging (GCM), you can save to a DB or Shared Preferences and comment out the line that displays the notification to the user. Then, you can use a background service to display it to the user whenever you like.
Upvotes: 0