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.
Asked
Active
Viewed 796 times
1

Libin
- 16,967
- 7
- 61
- 83
1 Answers
2
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;
}

ianhanniballake
- 191,609
- 30
- 470
- 443
-
1Thanks. How do i get the intent from the pending intent. It seem the `getIntent` is hidden and i'm getting exception if try to get the method using reflection. – Libin Jan 26 '18 at 20:05
-
2@Libin - that is intentionally impossible. The conversion from Intent to PendingIntent is a one way thing, specifically to make the Intent unmodifiable by other apps/the system. – ianhanniballake Jan 26 '18 at 20:11
-
1I've seen apps reading the notification and posting again . Don't know how they are able to read. When you tap on those notification they are able to launch the intent. – Libin Jan 26 '18 at 20:16
-
1One of the app is unnotification that you can undo the dismissed notification. The unnotification app will repost the notification and can also deeplink to the actual app posted when tapped. Wondering how this is working if we cannot read the content intent. – Libin Jan 26 '18 at 20:27
-
All of the Notification APIs take PendingIntents, not Intents. Absolutely no reason you need to go PendingIntent -> Intent -> PendingIntent. Just use the PendingIntent directly. – ianhanniballake Jan 26 '18 at 20:46
-
Thanks. That's right. Can we save the pending intent in a file or sqlite. – Libin Jan 26 '18 at 21:19
-
2No, PendingIntents are not persistable. – ianhanniballake Jan 26 '18 at 21:20
-
1@Libin did you get any solution for this? – Nouman Ch Feb 26 '19 at 11:57
-
No. I couldn't find any ways – Libin Feb 26 '19 at 12:00