Search code examples
androidandroid-intentandroid-notificationsandroid-notification-barandroid-statusbar

How to read the content intent from the notification


I'm using the NotificationListenerService to read the notification posted on the status bar. I'm able to read the title and text on the notifications , but couldn't find a way to read the actions and content intent set to the notification.

https://developer.android.com/reference/android/service/notification/NotificationListenerService.html


Solution

  • In your onNotificationPosted(), you have access to the StatusBarNotification. With that, you can call getNotification() and then use the public member variables contentIntent and actions to access the content intent and actions, respectively.

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
      Notificiation notification = sbn.getNotification();
    
      PendingIntent contentIntent = notification.contentIntent;
      Actions[] actions = notification.actions;
    }