Reputation: 2592
I have a NotificationListenerService class, which can read active notifications in the system.
All necessary permission are set, everything works as intended.
One easy question come however to me.
There is a notification with actions:
How can I "push" these buttons programmatically?
Upvotes: 0
Views: 631
Reputation: 2592
I forgot to check the fields of Notification
, where all Notification.Action
s are defined.
So you can get their actionIntent
and simply send it:
public static class MyNotificationListener extends NotificationListenerService {
public MyNotificationListener() {
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
try {
sbn.getNotification().actions[0].actionIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
}
Idea came from here: How to cancel an ongoing notification of another app?
Upvotes: 1