如何从通知中读取内容意图



我正在使用NotificationListenerService来阅读状态栏上发布的通知。我能够阅读通知上的标题和文本,但找不到读取设置为通知的操作和内容意图的方法。

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

在 onNotificationPosted(( 中,您可以访问 StatusBarNotification。有了它,你可以调用getNotification((,然后使用公共成员变量contentIntent和actions分别访问内容意图和动作。

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

最新更新