NotificationListenerService was introduced from Android team as part of API 18 (Android 4.3), this class allows an application to receive information from notifications when it's created and removed.
To use it we need to implement 2 callback methods. Both of them have paramether named sbn which is object of StatusBarNotification class.
In this example I will show quickly how to listen notification events with just print them to console.logs
Let's start with creating new Java Class named NotificationService.java with following content:
Also we need to update our Manifest file to include this newly created service.
So basically that is :) Run and enjoy :) Note: User require to enable notification permission from "Settings > Security > Notification access".