如何在 API 23 之前获取活动通知列表
How to get a list of active notifications prior API 23
下面的代码快照获取活动通知,但它需要 API 23+,其中我的代码 运行 21+
知道我的需求很简单,我只是想找出有活动通知的应用程序包,我不想读取通知数据,我不想取消它们。
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] n = notificationManager.getActiveNotifications();
for(int i = 0; i < n.length; i++) {
n[i].getPackageName();
}
您可以使用 NotificationListenerService
,其中有 getActiveNotifications()
方法!
下面的代码快照获取活动通知,但它需要 API 23+,其中我的代码 运行 21+
知道我的需求很简单,我只是想找出有活动通知的应用程序包,我不想读取通知数据,我不想取消它们。
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] n = notificationManager.getActiveNotifications();
for(int i = 0; i < n.length; i++) {
n[i].getPackageName();
}
您可以使用 NotificationListenerService
,其中有 getActiveNotifications()
方法!